feat: 集成限流器到服务

- main.go 初始化限流器(根据 Redis 可用性选择内存/Redis 实现)
- WebSocket handler 添加 query 消息限流(按 userID)
- Auth API 添加登录/注册限流(按 IP)
- refresh 和 logout 不限流(避免影响正常用户操作)
- 修复所有测试(传递 nil limiter 参数)
- 所有测试通过(包括 ws 和 api 集成测试)
This commit is contained in:
hhs
2026-06-21 00:00:24 +08:00
parent ea00939c13
commit 7adf81c6e5
6 changed files with 240 additions and 44 deletions

View File

@@ -47,7 +47,7 @@ func newTestRouter(svc auth.Service) *gin.Engine {
r := gin.New()
tm := auth.NewTokenManager("test-secret", 15*time.Minute, 7*24*time.Hour)
h := api.NewAuthHandler(svc, tm)
h.RegisterRoutes(r.Group("/api"))
h.RegisterRoutes(r.Group("/api"), nil) // 测试时不启用限流
return r
}
@@ -57,7 +57,7 @@ func newTestRouterWithToken(svc auth.Service) (*gin.Engine, *auth.TokenManager)
r := gin.New()
tm := auth.NewTokenManager("test-secret", 15*time.Minute, 7*24*time.Hour)
h := api.NewAuthHandler(svc, tm)
h.RegisterRoutes(r.Group("/api"))
h.RegisterRoutes(r.Group("/api"), nil) // 测试时不启用限流
return r, tm
}