mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-26 03:47:43 +00:00
18 lines
310 B
Go
18 lines
310 B
Go
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
|
|
}
|