From 81ab381551540adbd1953969154469ec329531ee Mon Sep 17 00:00:00 2001 From: Shizun Ge Date: Fri, 10 Feb 2023 22:26:31 -0800 Subject: [PATCH] use geohash of the country if city is not available. --- geoip.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/geoip.go b/geoip.go index 43b1d14..17227bb 100644 --- a/geoip.go +++ b/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 }