refactor: 拆分 middleware/router 为单一职责文件,新增站点设置管理页面
middleware: - 拆分 auth.go → auth.go + auth_token.go + auth_parser.go + auth_admin.go - 拆分 csrf.go → csrf.go + csrf_token.go - 拆分 ratelimit.go → ratelimit.go + ratelimit_core.go + ratelimit_cleanup.go - 修复 import 未使用/缺失问题 router: - 拆分 router.go → admin.go + api.go + frontend.go + deps_core.go + deps_extra.go feat(admin): 站点设置管理页面 - 新增 SSR 页面 /admin/site-settings(仅 Owner) - 审核开关 Toggle 即时保存 - 通用设置展示 - 侧边栏新增站点设置入口 - 注册 UpdateBoolSetting/GetBoolSetting API 路由
This commit is contained in:
32
internal/middleware/ratelimit_cleanup.go
Normal file
32
internal/middleware/ratelimit_cleanup.go
Normal file
@ -0,0 +1,32 @@
|
||||
package middleware
|
||||
|
||||
import "time"
|
||||
|
||||
// Clear 登录成功后清除该 email 和 IP 的失败计数
|
||||
func (rl *RateLimiter) Clear(email, ip string) {
|
||||
rl.mu.Lock()
|
||||
defer rl.mu.Unlock()
|
||||
delete(rl.accountFailures, email)
|
||||
delete(rl.ipFailures, ip)
|
||||
}
|
||||
|
||||
// cleanupLoop 定期清理过期条目
|
||||
func (rl *RateLimiter) cleanupLoop() {
|
||||
ticker := time.NewTicker(cleanupInterval)
|
||||
defer ticker.Stop()
|
||||
for range ticker.C {
|
||||
rl.mu.Lock()
|
||||
now := time.Now()
|
||||
clean := func(m map[string]*windowState) {
|
||||
for k, v := range m {
|
||||
if (v.blockedUntil.IsZero() || now.After(v.blockedUntil)) &&
|
||||
now.Sub(v.windowStart) > accountWindow+ipBlockDur {
|
||||
delete(m, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
clean(rl.accountFailures)
|
||||
clean(rl.ipFailures)
|
||||
rl.mu.Unlock()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user