A fast, lightweight web service written in Rust (using Axum) that provides Geolocation, Weather, and Timezone/Datetime information based on IP addresses.
It uses MaxMind DB for local IP geolocation and the OpenWeather API for weather data.
- IP Geolocation: Get detailed geographic information (City, Country, Coordinates, Timezone) for a given IP address or the caller's IP.
- Weather Data: Current weather conditions based on the geolocation of the IP address.
- Weather Forecast: Weather forecast based on the geolocation of the IP address.
- Datetime Information: Current local time and timezone details for the IP address.
- Caching: Implements in-memory caching (using
moka) for weather and forecast data to minimize external API calls. - Docker Ready: Includes a
Dockerfileanddocker-compose.yamlfor easy deployment.
- MaxMind GeoLite2 Database: You need a MaxMind City database file (
city.mmdb). You can download a free GeoLite2 City database from MaxMind. - OpenWeather API Key: Sign up at OpenWeather to get a free API key for weather data.
- Rust & Cargo (for local development): If you wish to build from source.
- Docker & Docker Compose (for containerized deployment): Recommended for running the service.
-
Clone the repository:
git clone <repository-url> cd geoip
-
Environment Variables: Copy the example
.envfile and fill in your secrets.cp .env.example .env
Edit
.envand set:OPENWEATHER_API_KEY: Your OpenWeather API Key.
-
MaxMind Database: Place your
city.mmdbfile in the root of the project or update the path indocker-compose.yamlto point to its location. By default, thedocker-compose.yamlexpects it at/city.mmdbinside the container, which you might want to mount as a volume.
The easiest way to run the service is using Docker Compose.
You can use the prebuilt image published to Docker Hub, or build it locally.
Create a docker-compose.yaml file:
version: "3"
services:
geoip:
image: ljufa/geoip:latest
container_name: geoip
restart: unless-stopped
ports:
- "8080:8080"
environment:
- SERVER_BIND_ADDRESS=0.0.0.0:8080
- DB_FILE_PATH=/city.mmdb
- RUST_LOG=geoip=info,tower_http=info,hyper=info
- OPENWEATHER_API_KEY=${OPENWEATHER_API_KEY}
volumes:
- ./city.mmdb:/city.mmdb:roRun it using:
docker-compose up -dIf you have the source code, you can build and run it using the provided docker-compose.yaml:
docker-compose up -d --buildThis will build the Docker image and start the geoip service, exposing it on port 8080.
GET /iporGET /ip/:ipReturns geolocation data for the caller's IP or the specified IP address.GET /weatherorGET /weather/:ipReturns current weather data for the location of the caller's IP or the specified IP address.GET /weather/forecastorGET /weather/forecast/:ipReturns the weather forecast for the location of the caller's IP or the specified IP address.GET /datetimeorGET /datetime/:ipReturns the current date and time for the timezone associated with the caller's IP or the specified IP address.
To run the project locally without Docker:
export DB_FILE_PATH=./data/city.mmdb # Path to your MaxMind DB
export OPENWEATHER_API_KEY=your_api_key
export SERVER_BIND_ADDRESS=0.0.0.0:8080
cargo runMIT License