From 4698b744ff45c7ffa4674daec0bceffab48cd6ef Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Sun, 18 Oct 2020 18:53:15 +0200 Subject: better handle spaces --- main.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index e883834..a7fa072 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,6 @@ import ( "net" "net/http" "os" - "regexp" "strconv" "strings" "time" @@ -142,23 +141,21 @@ func (g *geodb) getRecordForIP(ipstr string) *geoip2.City { } func geolocateCity(city string) coordinates { - // because some cities apparently are not good enough for the top 10k + // some cities are missing from our top-10k list missingCities := make(map[string]coordinates) - missingCities["hongkong"] = coordinates{22.319201099, 114.1696121} + missingCities["hong kong"] = coordinates{22.319201099, 114.1696121} - re := regexp.MustCompile("-| ") for _, c := range cities.Cities { - canonical := strings.ToLower(city) - canonical = re.ReplaceAllString(canonical, "") - if strings.ToLower(c.City) == canonical { + if strings.ToLower(c.City) == strings.ToLower(city) { return coordinates{c.Latitude, c.Longitude} } - v, ok := missingCities[canonical] + v, ok := missingCities[city] if ok == true { return v } } + log.Println("WARN: cannot geolocate", city, "- make sure to add manual coordinates to getmyip") return coordinates{0, 0} } -- cgit v1.2.3