diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2020-10-18 18:53:15 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2020-10-18 18:53:15 +0200 |
commit | 4698b744ff45c7ffa4674daec0bceffab48cd6ef (patch) | |
tree | bb6e43f23980f9a2aec3f2784f350af47e21f27b | |
parent | f044f74a7077464e2ee99c8c4df67808d9031dcb (diff) |
better handle spaces
-rw-r--r-- | main.go | 13 |
1 files changed, 5 insertions, 8 deletions
@@ -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} } |