This is the Go implementation of the Maxmind GeoIP API. It is incomplete and work in progress the initial goal is support only two of the database types – the City Lite and Country Lite. The only supported method is loading the full db on startup into memory (memory cache).
- In Memory (Load(string))
- Country Edition (dbType=1)
- City Edition REV 0 (dbType=6)
- City Edition REV 1 (dbType=2)
- By IP Address (GetLocationByIP(string))
- By IP Number (GetLocationByIPNum(uint32))
- CountryCode string (available in all databases)
- CountryName string (available in all databases)
- Continent string (available in all databases)
- City string
- Region string
- PostalCode string
- Latitude float32
- Longitude float32
- Implement better error handling (report the error on load and lookups)
- Better returns, country edition has only code and name (perhaps use interfaces)
- Add test cases and benchmarking
- Add support for more database formats
Usage
gi, err := geoip.Load(dbFile)
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return
}
loc := gi.GetLocationByIP(ipAddr)
println(loc.CountryName)
gi, err := geoip.Load(dbFile)
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return
}
loc := gi.GetLocationByIP(ipAddr)
println(loc.CountryName)