fix middleware

This commit is contained in:
白茶清欢 2024-09-24 15:05:02 +08:00
parent 5ae2e3fae1
commit 29b0eaa6b3

View File

@ -26,9 +26,12 @@ func ValidateBlackIPMiddleware(code interface{}, httpCode int, validateFunc defi
ctx.Next() ctx.Next()
return return
} }
if validateFunc(ctx, networkUtil.IP.GetRemoteIP(ctx.Request)) { remoteIp := networkUtil.IP.GetRemoteIP(ctx.Request)
if validateFunc(ctx, remoteIp) {
// 命中黑名单 // 命中黑名单
response.Send(ctx, code, httpCode, nil) response.Send(ctx, code, httpCode, map[string]any{
"remote_ip": remoteIp,
}, nil)
ctx.Abort() ctx.Abort()
return return
} }
@ -48,9 +51,12 @@ func ValidateWhiteIPMiddleware(code interface{}, httpCode int, validateFunc defi
ctx.Next() ctx.Next()
return return
} }
if !validateFunc(ctx, networkUtil.IP.GetRemoteIP(ctx.Request)) { remoteIp := networkUtil.IP.GetRemoteIP(ctx.Request)
if !validateFunc(ctx, remoteIp) {
// 非名单 // 非名单
response.Send(ctx, code, httpCode, nil) response.Send(ctx, code, httpCode, map[string]any{
"remote_ip": remoteIp,
}, nil)
ctx.Abort() ctx.Abort()
return return
} }