refactor🎨: 调整客户端ip获取方法以及日志中对应位置更新
This commit is contained in:
1 parent
ed52efaa44
commit
e0cf7af7a9
4 files changed
+28
-10
No files matched your search
@@ -0,0 +1,17 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetClientIP(ctx *gin.Context) string {
|
||||
ip := ctx.Request.Header.Get("X-Forwarded-For")
|
||||
if strings.Contains(ip, "127.0.0.1") || ip == "" {
|
||||
ip = ctx.Request.Header.Get("X-real-ip")
|
||||
}
|
||||
if ip == "" {
|
||||
return "127.0.0.1"
|
||||
}
|
||||
return ip
|
||||
}
|
||||
Reference in new issue
Block a user