切换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

3
go.mod
View File

@ -4,7 +4,7 @@ go 1.20
require (
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20230609101214-16920b714d94
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230810035709-c318ed9f367d
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230810063945-842592611562
github.com/gin-gonic/gin v1.9.1
github.com/go-playground/validator/v10 v10.15.0
github.com/pkg/errors v0.9.1
@ -13,6 +13,7 @@ require (
)
require (
git.zhangdeman.cn/zhangdeman/network v0.0.0-20230810064349-0948cd51c01d // indirect
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20230810031624-94c86f913f9c // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/Jeffail/gabs v1.4.0 // indirect

4
go.sum
View File

@ -2,10 +2,14 @@ git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220703050824-0679ce509241 h1:tBa
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20220703050824-0679ce509241/go.mod h1:mIMM/t9BkrKHAcDCmarLCHQhHfWf0/ZjtcqJPboqmSA=
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20230609101214-16920b714d94 h1:0A37IoVHd71aUADVueGE6MEUPFsakQS7KYHhwKd9MEE=
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20230609101214-16920b714d94/go.mod h1:Voc8J4ordx7nuMWpgACXXZULQy7ZIuBzcEIoS8VnDIw=
git.zhangdeman.cn/zhangdeman/network v0.0.0-20230810064349-0948cd51c01d h1:xDIqlRdXIM5U87dZCR2ua9uZ0cI8ryv12mLkinWdUFM=
git.zhangdeman.cn/zhangdeman/network v0.0.0-20230810064349-0948cd51c01d/go.mod h1:BPahs8KYF7x/YHB46oCMZXR8asEX48ZnwUGI0px9UiI=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220714054940-3cfcad0c6547 h1:ieuPrfZDDgwz9ANQdXQrGNWlKWN6bK3qOUC+XUAITrk=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220714054940-3cfcad0c6547/go.mod h1:zTir/0IWdK3E7n0GiaogyWHADAQnBtTdl2I6Z2/OPqw=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230810035709-c318ed9f367d h1:oju8MKvJ82l0P0I3mnKrhcF3yw9Ck3AqOPh8fM0g32w=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230810035709-c318ed9f367d/go.mod h1:trYFOShINaQBvinQrH4A0G2kfL22Y2lygEcAiGDt/sc=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230810063945-842592611562 h1:wo0r4mexqkPzQ1SZOw5z8A7FJ3ne1G6A/qWR3iaqlhw=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230810063945-842592611562/go.mod h1:trYFOShINaQBvinQrH4A0G2kfL22Y2lygEcAiGDt/sc=
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20230810031624-94c86f913f9c h1:n7lws3x/eR4DlcubTMepiLEgJikSN22sHYqJRaYWIkg=
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20230810031624-94c86f913f9c/go.mod h1:pL3BbQdogtClFCrsiAyzBIQRWKSSIf3v2GuzZu6dGWY=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=

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()