commit b4cb819fe26aa013fa744e8b859d01c991733805
parent 735b6224624225e848ba516fbe581dc1c3a3d341
Author: dwrz <dwrz@dwrz.net>
Date: Wed, 10 Dec 2025 23:36:48 +0000
Add geo pkg
Diffstat:
1 file changed, 34 insertions(+), 0 deletions(-)
diff --git a/pkg/geo/geo.go b/pkg/geo/geo.go
@@ -0,0 +1,34 @@
+package geo
+
+import (
+ "fmt"
+ "strconv"
+ "strings"
+)
+
+type Coordinates struct {
+ Latitude float64
+ Longitude float64
+}
+
+func ParseCoordinates(s string) (*Coordinates, error) {
+ parts := strings.Split(s, ",")
+ if len(parts) != 2 {
+ return nil, fmt.Errorf("invalid string: %s", s)
+ }
+
+ var (
+ c = &Coordinates{}
+ err error
+ )
+ c.Latitude, err = strconv.ParseFloat(parts[0], 64)
+ if err != nil {
+ return nil, fmt.Errorf("failed to parse latitude: %v", err)
+ }
+ c.Longitude, err = strconv.ParseFloat(parts[1], 64)
+ if err != nil {
+ return nil, fmt.Errorf("failed to parse longitude: %v", err)
+ }
+
+ return c, nil
+}