use geohash of the country if city is not available.
This commit is contained in:
parent
d9202cfca6
commit
81ab381551
1 changed files with 4 additions and 0 deletions
4
geoip.go
4
geoip.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue