diff options
-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} } |