Crates.io | actix-governor |
lib.rs | actix-governor |
version | |
source | src |
created_at | 2020-12-27 20:28:58.41739 |
updated_at | 2024-12-12 15:21:16.951776 |
description | A rate-limiting middleware for actix-web backed by the governor crate |
homepage | |
repository | https://github.com/AaronErhardt/actix-governor |
max_upload_size | |
id | 327979 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A middleware for actix-web that provides rate-limiting backed by governor.
use actix_governor::{Governor, GovernorConfigBuilder};
use actix_web::{web, App, HttpServer, Responder};
async fn index() -> impl Responder {
"Hello world!"
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
// Allow bursts with up to five requests per IP address
// and replenishes two elements per second
let governor_conf = GovernorConfigBuilder::default()
.requests_per_second(2)
.burst_size(5)
.finish()
.unwrap();
HttpServer::new(move || {
App::new()
// Enable Governor middleware
.wrap(Governor::new(&governor_conf))
// Route hello world service
.route("/", web::get().to(index))
})
.bind("127.0.0.1:8080")?
.run()
.await
}
Cargo.toml
:[dependencies]
actix-governor = "0.6"