1
0
Fork 0

fetch: merge geolocation types

This commit is contained in:
Johannes Kimmel 2024-03-11 10:22:28 +01:00
parent 47cb18592a
commit 41179fbcf5
2 changed files with 13 additions and 19 deletions

View File

@ -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
}

View File

@ -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"`
}