1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Copyright (c) 2026, Kirky.X
//!
//! MIT License
//!
//! Tower 中间件层
//!
//! 提供基于 Tower Service/Layer 的 HTTP 中间件实现,将 Governor 流量控制
//! 集成到 Rust Web 框架(如 Axum、Hyper、Tower-http)中。
//!
//! # 架构
//!
//! ```text
//! Request → RateLimitLayer → RateLimitService → Inner Service
//! ↓
//! Governor.check()
//! ↓
//! 注入响应头 → Response
//! ```
//!
//! # 使用示例
//!
//! ```rust,no_run
//! use limiteron::middleware::{RateLimitLayer, RateLimitConfig};
//! use limiteron::Governor;
//! use std::sync::Arc;
//!
//! #[tokio::main]
//! async fn main() {
//! // 创建 Governor 实例
//! let governor = Governor::new().await;
//!
//! // 创建限流中间件层
//! let layer = RateLimitLayer::new(
//! Arc::new(governor),
//! RateLimitConfig::default(),
//! );
//!
//! // 与 Tower 服务链集成
//! // let service = layer.make_service(inner_service);
//! }
//! ```
//!
//! # 响应头
//!
//! 中间件会自动注入标准限流响应头:
//! - `RateLimit-Limit`: 限流上限
//! - `RateLimit-Remaining`: 剩余可用次数
//! - `RateLimit-Reset`: 重置时间戳(Unix 秒)
//! - `Retry-After`: 重试等待时间(秒,仅在请求被拒绝时)
// 子模块
// 重新导出公共类型
pub use ;
pub use ;