From 41179fbcf50534645ad180f0ec48b80a37ba7f03 Mon Sep 17 00:00:00 2001 From: Johannes Kimmel Date: Mon, 11 Mar 2024 10:22:28 +0100 Subject: [PATCH] fetch: merge geolocation types --- cmd/fetch/fetch.go | 11 +++++------ cmd/fetch/types.go | 21 ++++++++------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/cmd/fetch/fetch.go b/cmd/fetch/fetch.go index 54af0df..3a80bcc 100644 --- a/cmd/fetch/fetch.go +++ b/cmd/fetch/fetch.go @@ -13,7 +13,7 @@ const UPSTREAM_URL = "https://keyserver.freifunk-franken.de/v2/" func run() error { var root []root - err := os.Mkdir("hoods", 0777) + err := os.MkdirAll("hoods", 0777) if err != nil { return err } @@ -43,12 +43,9 @@ func run() error { } if len(h.Polygons) == 0 { - hood.Location = []HoodCoordinate{{Lat: h.Lat, Long: h.Long}} + hood.Location = []GeoCoordinate{{Lat: h.Lat, Long: h.Long}} } else { - hood.Location = []HoodCoordinate{} - for _, p := range h.Polygons[0] { - hood.Location = append(hood.Location, HoodCoordinate{Lat: p.Lat, Long: p.Long}) - } + hood.Location = h.Polygons[0] } b, err := json.MarshalIndent(hood, "", " ") @@ -60,6 +57,8 @@ func run() error { if err != nil { return err } + + log.Printf("%s\n", hood.HoodInfo.Name) } return nil } diff --git a/cmd/fetch/types.go b/cmd/fetch/types.go index e8445af..96a69ec 100644 --- a/cmd/fetch/types.go +++ b/cmd/fetch/types.go @@ -1,16 +1,16 @@ package main type root struct { - Id uint `json:"id"` - Active uint `json:"active"` - Name string `json:"name"` - Lat float64 `json:"lat"` - Long float64 `json:"lon"` - Polygons [][]InputCoordinate `json:"polygons"` + Id uint `json:"id"` + Active uint `json:"active"` + Name string `json:"name"` + Lat float64 `json:"lat"` + Long float64 `json:"lon"` + Polygons [][]GeoCoordinate `json:"polygons"` Hood Hood } -type InputCoordinate struct { +type GeoCoordinate struct { Lat float64 `json:"lat"` Long float64 `json:"lon"` } @@ -24,7 +24,7 @@ type Hood struct { // one coordinate: voronoi // two coordinates: invalid // three or more coordinates: polygon - Location []HoodCoordinate `json:"location,omitempty"` + Location []GeoCoordinate `json:"location,omitempty"` } type HoodNetwork struct { @@ -58,8 +58,3 @@ type HoodInfo struct { NtpIp string `json:"ntp_ip"` Timestamp uint64 `json:"timestamp"` } - -type HoodCoordinate struct { - Lat float64 `json:"lat"` - Long float64 `json:"lon"` -}