IP Info
A web application for getting information about an IP address based on MaxMind Database.
Technologies and architecture
- Written in Golang
- Gin framework for HTTP routing and serving HTTP
- Implemented Hexagonal Architecture and Dependency Injection
- Unit tested all functionalities
- Integration tested the HTTP adapter.
- Mocked MaxMind repository and Business Logic
Deployment
- Clone the repository
- Create a .env file
mv .env.sample .env
- Change environment variables as desired
- Download MaxMind Database files
make download_mmdb
- Build and run using docker-compose
make build && make run
Run tests
First of all, generate mocks using make generate_mocks
. Then you must put ".mmdb" files into internal/adapters/maxmind/tmp.
Now you can run tests using the command below:
make test
Endpoints
METHOD: GET
QUERY STRINGS:
- continent: bool (true|false, default: true)
- country: bool (true|false, default: true)
- city: bool (true|false, default: true)
- asn: bool (true|false, default: true)\
DESCRIPTION: Returns the full information of the client IP
USAGE:
curl "http://localhost:5000/" | jq
METHOD: GET
QUERY STRINGS: Same as above
DESCRIPTION: Returns the full information of the given IP in path parameter
USAGE:
curl "http://localhost:5000/8.8.8.8" | jq
METHOD: GET
QUERY STRINGS: NONE
DESCRIPTION: Returns the short information of the client IP in path parameter
USAGE:
curl "http://localhost:5000/short" | jq
METHOD: GET
QUERY STRINGS: NONE
DESCRIPTION: Returns the short information of the given IP in path parameter
USAGE:
curl "http://localhost:5000/8.8.8.8/short" | jq
Alias in Terminal
If you want to get information about an IP just using a command, instead of writing curl https://localhost:5000
you can just set an alias in your shell configuration file:
alias ipinfo=curl -sk "http://localhost:5000/$1/short" | jq
Just put this in your shell configuration file like ~/.bashrc
or ~/.zshrc
and run source ~/.bashrc(or zshrc)
Future Plans
- Documenting using Swagger
- Cleaner tests and more test cases