16 个版本
0.5.0 | 2023 年 10 月 4 日 |
---|---|
0.4.1 | 2023 年 6 月 20 日 |
0.4.0 | 2023 年 1 月 15 日 |
0.4.0-beta.3 | 2022 年 12 月 5 日 |
0.2.3 | 2020 年 12 月 31 日 |
152 在 HTTP 服务器 中
每月 8,206 次下载
在 6 个 crate 中使用
82KB
1.5K SLoC
Actix Governor
由 actix-web 提供速率限制支持的中间件 governor。
特性
- 易于使用
- 高度可定制
- 高性能
- 健壮且灵活的 API
示例
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 one element every two seconds
let governor_conf = GovernorConfigBuilder::default()
.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.4"
依赖项
~17–29MB
~515K SLoC