Skip to main content

Module geolocation

Module geolocation 

Source
Expand description

§modo::geolocation

IP-to-location lookup using a MaxMind GeoLite2/GeoIP2 .mmdb database.

§Provides

§Quick start

  1. Configure mmdb_path in the geolocation section of your YAML config.
  2. Build a GeoLocator at startup with GeoLocator::from_config.
  3. Add ClientIpLayer before GeoLayer in your middleware stack so client IP resolution happens first.
  4. Use Location as an axum extractor in handlers to read the resolved geolocation for each request.
let config = GeolocationConfig { mmdb_path: "data/GeoLite2-City.mmdb".into() };
let locator = GeoLocator::from_config(&config)?;

let app = Router::new()
    .route("/", get(handler))
    .layer(GeoLayer::new(locator))
    .layer(ClientIpLayer::new());

async fn handler(location: Location) -> String {
    format!("country: {:?}", location.country_code)
}

Structs§

GeoLayer
Tower layer that performs geolocation lookup and inserts Location into request extensions.
GeoLocator
MaxMind GeoLite2/GeoIP2 database reader.
GeolocationConfig
Configuration for the geolocation module.
Location
Geolocation data resolved from a client IP address.