Исходники и презентации
This commit is contained in:
26
lessons/errors/many_times_handling_2/main.go
Normal file
26
lessons/errors/many_times_handling_2/main.go
Normal file
@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func GetRoute(lat, lon float32) (string, error) {
|
||||
err := validateCoordinates(lat, lon)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("validation error: %w", err)
|
||||
}
|
||||
|
||||
return "route", nil
|
||||
}
|
||||
|
||||
func validateCoordinates(lat, lon float32) error {
|
||||
if lat > 90. || lat < -90. {
|
||||
return errors.New("incorrect latitude")
|
||||
}
|
||||
if lon > 180. || lon < -180. {
|
||||
return errors.New("incorrect longitude")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user