-
Couldn't load subscription status.
- Fork 104
Closed
Labels
Description
When the ip address is not found in the database the library doesn't return an error.
I was able to reproduce this problem using the latest GeoLite2-City.mmdb and the ip address 102.53.124.191. From what I can see at https://www.maxmind.com/en/geoip2-city-database-accuracy MaxMind doesn't promise to resolve all ip addresses so it seems useful to return an error when the ip address can not be found.
Here is code that shows the issue:
package main import ( "fmt" "log" "net" "os" "github.com/oschwald/maxminddb-golang" ) type City struct { City struct { GeoNameID uint `maxminddb:"geoname_id"` Names map[string]string `maxminddb:"names"` } `maxminddb:"city"` Country struct { GeoNameID uint `maxminddb:"geoname_id"` IsoCode string `maxminddb:"iso_code"` Names map[string]string `maxminddb:"names"` } `maxminddb:"country"` Location struct { Latitude float64 `maxminddb:"latitude"` Longitude float64 `maxminddb:"longitude"` } `maxminddb:"location"` } func main() { geodbfile := "GeoLite2-City.mmdb" if os.Getenv("GEODB") != "" { geodbfile = os.Getenv("GEODB") } db, err := maxminddb.Open(geodbfile) if err != nil { log.Fatal(err) } defer db.Close() ip := net.ParseIP("102.53.124.191") var city City err = db.Lookup(ip, &city) if err == nil { fmt.Println("Didn't get an error but expected one") } fmt.Println(city, err) }