GeoIP (with MaxMind databases)
This is an alternative method to resolve IP addresses to real-world location data using MaxMind GeoLite2 City databases.
Prerequisitesβ
Before you run this, you must first download a database from the MaxMind website - https://dev.maxmind.com/geoip/geoip2/geolite2/. To do this, you may need to register for a free account.
The database you need to download is the one with the edition ID GeoLite2-City
. Place it in this folder and run
go run geoip-maxmind
Usageβ
Make a request to http://127.0.0.1:3000/geo/178.62.56.160
, for example. You can omit an IP address to use your current IP address, or replace to use another. If the IP address is invalid, a HTTP 400 is returned.
The response fields can be modified from the ipLookup
struct, found in the handlers/handlers.go
file.
Example responseβ
{
"City": {
"GeoNameID": 2643743,
"Names": {
"de": "London",
"en": "London",
"es": "Londres",
"fr": "Londres",
"ja": "γγ³γγ³",
"pt-BR": "Londres",
"ru": "ΠΠΎΠ½Π΄ΠΎΠ½",
"zh-CN": "δΌ¦ζ¦"
}
},
"Country": {
"IsoCode": "GB"
},
"Location": {
"AccuracyRadius": 50
}
}