Expand description
§modo::geolocation
IP-to-location lookup using a MaxMind GeoLite2/GeoIP2 .mmdb database.
§Provides
GeolocationConfig— YAML-deserializable config withmmdb_pathGeoLocator— MaxMind database reader; cheaply cloneable viaArcGeoLayer— Tower layer that resolves location per request; also re-exported asmodo::middlewares::GeoLocation— resolved geolocation data; doubles as an axum extractor
§Quick start
- Configure
mmdb_pathin thegeolocationsection of your YAML config. - Build a
GeoLocatorat startup withGeoLocator::from_config. - Add
ClientIpLayerbeforeGeoLayerin your middleware stack so client IP resolution happens first. - Use
Locationas 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
Locationinto request extensions. - GeoLocator
- MaxMind GeoLite2/GeoIP2 database reader.
- Geolocation
Config - Configuration for the geolocation module.
- Location
- Geolocation data resolved from a client IP address.