A Tower service and layer that provides a rate-limiting backed by governor. Based heavily on the work done for actix-governor. Works with Axum, Hyper, Tower, Tonic, and anything else based on Tower!

# Features:

async fn hello() -> &'static str { "Hello world" }

[tokio::main]

async fn main() { // Allow bursts with up to five requests per IP address // and replenishes one element every two seconds let governorconf = GovernorConfigBuilder::default() .persecond(2) .burstsize(5) .finish() .unwrap(); // build our application with a route let app = Router::new() // GET / goes to root .route("/", get(hello)) .layer(GovernorLayer { config: &governorconf, });

// run our app with hyper
// `axum::Server` is a re-export of `hyper::Server`
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
    .serve(app.into_make_service_with_connect_info::<SocketAddr>())
    .await
    .unwrap();

} ```

# Configuration presets

Instead of using the configuration builder you can use predefined presets.