mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-22 04:34:27 +00:00
- Remove unused imports: governor clock/state/Quota, std::num::NonZeroU32, std::sync::Arc, and SmartIpKeyExtractor - Change create_rate_limiter return type from explicit generic parameters to simple GovernorLayer - Replace custom rate limit configuration (RATE_LIMIT_RPS, RATE_LIMIT_BURST environment variables) with GovernorConfig::default() - Remove quota builder logic and pass config directly to GovernorLayer::new()
23 lines
494 B
Rust
23 lines
494 B
Rust
use axum::{
|
|
http::StatusCode,
|
|
response::{IntoResponse, Response},
|
|
};
|
|
use tower_governor::{
|
|
governor::GovernorConfig,
|
|
GovernorLayer,
|
|
};
|
|
|
|
pub fn create_rate_limiter() -> GovernorLayer {
|
|
let governor_conf = GovernorConfig::default();
|
|
|
|
GovernorLayer::new(governor_conf)
|
|
}
|
|
|
|
pub struct RateLimitResponse;
|
|
|
|
impl IntoResponse for RateLimitResponse {
|
|
fn into_response(self) -> Response {
|
|
(StatusCode::TOO_MANY_REQUESTS, "Rate limit exceeded").into_response()
|
|
}
|
|
}
|