Golang project for looking up geo from an IP. Meant to be deployed on Render.
In order to use this project, you'll need a copy of your own Maxmind GeoIP database. You can sign up for the GeoLite2 database here.
This project then relies on the oschwald/geoip2-golang package for looking up an IP in a MaxMind GeoIP database. See the documentation for all of the queries that can be made and the resulting structs.
This project relies on the following environment variables:
ENV Variable | Description | Required | Default |
---|---|---|---|
GEO_FILE |
The location of your Maxmind GeoIP database (e.g., ./GeoLite2-City.mmdb ) |
Yes | None |
MODE |
The mode to launch the application in. | No | "release" |
PORT |
The port for the web service to listen on. | No | 3000 |
Fork this repository into your own account.
Include your Maxmind GeoIP database in the root of the project. For example, ./GeoLite2-City.mmdb
. Commit this to the repository.
Update the handler()
function in main.go
to make the appropriate query and return the response.
The example in main.go
uses the IP address provided to make a City()
query and returns the zip code as JSON.
Create a new web service on Render. Use your new repository and set the above environment variables to make them available at run time.
The web service listens for requests to /:ipaddress
.
- This project DOES NOT log web requests. It only prints status logs. If you want to log each request, you can add it to the Go Gin logger.
- The web service responds to a
200
status code on/healthz
, to be used as a health check.