diff --git a/middleware/ip_validate.go b/middleware/ip_validate.go index 8df84d8..9052095 100644 --- a/middleware/ip_validate.go +++ b/middleware/ip_validate.go @@ -26,9 +26,12 @@ func ValidateBlackIPMiddleware(code interface{}, httpCode int, validateFunc defi ctx.Next() 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() return } @@ -48,9 +51,12 @@ func ValidateWhiteIPMiddleware(code interface{}, httpCode int, validateFunc defi ctx.Next() 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() return }