Some checks failed
Build / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
build / Build (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitee (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitlab (push) Has been cancelled
Issue Close Require / issue-close-require (push) Has been cancelled
Issue Check Inactive / issue-check-inactive (push) Has been cancelled
28 lines
528 B
Go
28 lines
528 B
Go
package common
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"strings"
|
|
)
|
|
|
|
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 = c.Request.Header.Get("X-real-ip")
|
|
}
|
|
if ip == "" {
|
|
ip = "127.0.0.1"
|
|
}
|
|
if RemoteIP != "127.0.0.1" {
|
|
ip = RemoteIP
|
|
}
|
|
if ClientIP != "127.0.0.1" {
|
|
ip = ClientIP
|
|
}
|
|
return ip
|
|
}
|