fix
This commit is contained in:
@@ -3,7 +3,6 @@ package middleware
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -91,7 +90,7 @@ func (m *DailyRateLimitMiddleware) GetPriority() int {
|
||||
}
|
||||
|
||||
// Handle 返回中间件处理函数
|
||||
func (c *DailyRateLimitMiddleware) Handle() gin.HandlerFunc {
|
||||
func (m *DailyRateLimitMiddleware) Handle() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
|
||||
@@ -151,7 +150,7 @@ func (c *DailyRateLimitMiddleware) Handle() gin.HandlerFunc {
|
||||
zap.String("request_id", c.GetString("request_id")),
|
||||
zap.Error(err))
|
||||
// 隐藏限制信息,返回通用错误
|
||||
m.response.InternalServerError(c, "系统繁忙,请稍后再试")
|
||||
m.response.InternalError(c, "系统繁忙,请稍后再试")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -163,7 +162,7 @@ func (c *DailyRateLimitMiddleware) Handle() gin.HandlerFunc {
|
||||
zap.String("request_id", c.GetString("request_id")),
|
||||
zap.Error(err))
|
||||
// 隐藏限制信息,返回通用错误
|
||||
m.response.InternalServerError(c, "系统繁忙,请稍后再试")
|
||||
m.response.InternalError(c, "系统繁忙,请稍后再试")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -171,7 +170,7 @@ func (c *DailyRateLimitMiddleware) Handle() gin.HandlerFunc {
|
||||
// 7. 增加计数
|
||||
m.incrementCounters(ctx, clientIP)
|
||||
|
||||
// 7. 添加隐藏的响应头(仅用于内部监控)
|
||||
// 8. 添加隐藏的响应头(仅用于内部监控)
|
||||
m.addHiddenHeaders(c, clientIP)
|
||||
|
||||
c.Next()
|
||||
@@ -414,7 +413,7 @@ func (m *DailyRateLimitMiddleware) getCounter(ctx context.Context, key string) (
|
||||
return 0, fmt.Errorf("解析计数失败: %w", err)
|
||||
}
|
||||
|
||||
return count
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// incrementCounter 增加计数器
|
||||
|
||||
Reference in New Issue
Block a user