feat(server): 限流 fail-close 统一配置
- 新增 RateLimitConfig 结构体,支持 config.toml + 环境变量 - apply_rate_limit 统一读取 fail_close 配置,生产环境可设为拒绝请求 - account_lockout_middleware 改为从 AppState.config 读取,不再直接读环境变量 - default.toml 添加 [rate_limit] 配置节
This commit is contained in:
@@ -14,6 +14,8 @@ pub struct AppConfig {
|
||||
pub crypto: CryptoConfig,
|
||||
pub ai: AiConfig,
|
||||
pub storage: StorageConfig,
|
||||
#[serde(default)]
|
||||
pub rate_limit: RateLimitConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
@@ -123,6 +125,19 @@ impl StorageConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct RateLimitConfig {
|
||||
/// Redis 不可达时是否拒绝请求(生产环境必须为 true)。
|
||||
#[serde(default)]
|
||||
pub fail_close: bool,
|
||||
}
|
||||
|
||||
impl Default for RateLimitConfig {
|
||||
fn default() -> Self {
|
||||
Self { fail_close: false }
|
||||
}
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
pub fn load() -> anyhow::Result<Self> {
|
||||
let config = config::Config::builder()
|
||||
|
||||
Reference in New Issue
Block a user