```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

refactor(login): 提取客户端IP到变量以优化速率限制逻辑

- 将 r.GetClientIp() 调用结果存储到 ip 变量中
- 在 AllowVisitByIP4 方法调用中使用该变量
- 保持相同的速率限制功能,但提高代码可读性
```
This commit is contained in:
昔念
2026-01-30 01:59:45 +08:00
parent 0c6d22d3f4
commit dd2a267194

View File

@@ -81,9 +81,10 @@ func Limiter(r *ghttp.Request) {
// 3. 为任意键 "some-key" 获取一个速率限制器
// - rate.Limit(2): 表示速率为 "每秒2个请求"
// - 2: 表示桶的容量 (Burst)允许瞬时处理2个请求
if !limiter.AllowVisitByIP4(r.GetClientIp()) {
ip := r.GetClientIp()
if !limiter.AllowVisitByIP4(ip) {
r.Response.WriteStatusExit(429) // Return 429 Too Many Requests
r.ExitAll()
}
r.Middleware.Next()