use geohash of the country if city is not available.

This commit is contained in:
Shizun Ge 2023-02-10 22:26:31 -08:00
parent d9202cfca6
commit 81ab381551

View file

@ -105,6 +105,10 @@ func geohashAndLocationFromMaxMindDb(address string) (string, string, string, er
// If you are using strings that may be invalid, check that ip is not nil
ip := net.ParseIP(address)
record, err := db.City(ip)
if err != nil {
// In case of using Country DB, city is not available.
record, err = db.Country(ip)
}
if err != nil {
return "s000", "Unknown", "Unknown", err
}