From 29b0eaa6b325ab42af813c0bbb7a4184908d3628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 24 Sep 2024 15:05:02 +0800 Subject: [PATCH] fix middleware --- middleware/ip_validate.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 }