Api endpoint to validate location of incoming IP Addresses
go run /Users/{you}/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.8.darwin-amd64/src/crypto/tls/generate_cert.go
https://dev.maxmind.com/geoip/updating-databases/ docker documentation
https://github.com/oschwald/geoip2-golang
{
"ip": "110.241.52.60",
"countryIsoCode": [
"US", "UA"
]
}
countryIsoCodes should be alpha-2 code from this list.
I submitted my version of the main.go file to ChatGpt and asked it to write tests. It wrote the main_test.go file and suggested I use an interface for the db, which I accepted. This commit shows the changes Chatgpt made.
to test go test -coverprofile=coverage.out
-
Follow instructions to download the database. Create and .env file with DB_LOCATION and PORT populated and source it. (
source my.env). -
Create cert.pem and key.pem files. [One way to do this](go run /Users/{you}/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.8.darwin-amd64/src/crypto/tls/generate_cert.go).
-
If you want to debug, create a launch file and debug. If not, run
go buildandgo run main.go. -
Use Postman to post a request to https://localhost:{your port from .env file} using the request body format mentioned earlier in this README file.
- Create an environment file like env.sample and source it.
- Run
docker compose up -d
This will run two containers. One is the canned geoipupdate container and expose the db file for the other container. My understanding is that this geoipupdate container will automatically update the db every x hours. I have it set to 72.
🚀 Chatgpt helped me tremendously with the Dockerfile for the go service.