diff --git a/common/global/adm.go b/common/global/adm.go index 6081753b..cde84ec1 100644 --- a/common/global/adm.go +++ b/common/global/adm.go @@ -2,7 +2,7 @@ package global const ( // Version go-admin version info - Version = "2.0.0-beta.3" + Version = "2.0.0-beta.4" ) var ( diff --git a/common/ip.go b/common/ip.go index bc8b97f6..7822f259 100644 --- a/common/ip.go +++ b/common/ip.go @@ -1,17 +1,29 @@ package common import ( + "fmt" "github.com/gin-gonic/gin" "strings" ) -func GetClientIP(ctx *gin.Context) string { - ip := ctx.Request.Header.Get("X-Forwarded-For") +func GetClientIP(c *gin.Context) string { + ClientIP := c.ClientIP() + fmt.Println("ClientIP:", ClientIP) + RemoteIP, _ := c.RemoteIP() + fmt.Println("RemoteIP:", RemoteIP) + ip := c.Request.Header.Get("X-Forwarded-For") if strings.Contains(ip, "127.0.0.1") || ip == "" { - ip = ctx.Request.Header.Get("X-real-ip") + ip = c.Request.Header.Get("X-real-ip") } if ip == "" { - return "127.0.0.1" + ip = "127.0.0.1" } + if RemoteIP.String() != "127.0.0.1" { + ip = RemoteIP.String() + } + if ClientIP != "127.0.0.1" { + ip = ClientIP + } + fmt.Println("ip:", ip) return ip }