切换util工具函数

This commit is contained in:
2023-08-10 14:47:20 +08:00
parent 5e1aaaf64e
commit c93cf01fe0
4 changed files with 12 additions and 6 deletions

View File

@ -14,6 +14,7 @@ import (
"git.zhangdeman.cn/zhangdeman/gin/define"
networkUtil "git.zhangdeman.cn/zhangdeman/network/util"
"git.zhangdeman.cn/zhangdeman/util"
"github.com/gin-gonic/gin"
)
@ -43,8 +44,8 @@ func getTraceID(ctx *gin.Context) string {
return fmt.Sprintf(
"%v-%v-%v-%v",
time.Now().UnixNano()/1e6,
strings.ReplaceAll(util.IP.GetHostIP(), ".", ""),
strings.ReplaceAll(util.IP.GetRemoteIP(ctx.Request), ".", ""),
strings.ReplaceAll(networkUtil.IP.GetHostIP(), ".", ""),
strings.ReplaceAll(networkUtil.IP.GetRemoteIP(ctx.Request), ".", ""),
util.String.Md5(util.String.GenRandom("", 32)),
)
}

View File

@ -10,7 +10,7 @@ package middleware
import (
"git.zhangdeman.cn/zhangdeman/gin/define"
"git.zhangdeman.cn/zhangdeman/gin/response"
"git.zhangdeman.cn/zhangdeman/util"
networkUtil "git.zhangdeman.cn/zhangdeman/network/util"
"github.com/gin-gonic/gin"
)
@ -26,7 +26,7 @@ func ValidateBlackIPMiddleware(code interface{}, httpCode int, validateFunc defi
ctx.Next()
return
}
if validateFunc(ctx, util.IP.GetRemoteIP(ctx.Request)) {
if validateFunc(ctx, networkUtil.IP.GetRemoteIP(ctx.Request)) {
// 命中黑名单
response.Send(ctx, code, httpCode, nil)
ctx.Abort()
@ -48,7 +48,7 @@ func ValidateWhiteIPMiddleware(code interface{}, httpCode int, validateFunc defi
ctx.Next()
return
}
if !validateFunc(ctx, util.IP.GetRemoteIP(ctx.Request)) {
if !validateFunc(ctx, networkUtil.IP.GetRemoteIP(ctx.Request)) {
// 非名单
response.Send(ctx, code, httpCode, nil)
ctx.Abort()