diff options
| author | mhsanaei <ho3ein.sanaei@gmail.com> | 2024-05-23 16:16:13 +0300 |
|---|---|---|
| committer | mhsanaei <ho3ein.sanaei@gmail.com> | 2024-05-23 16:16:13 +0300 |
| commit | 5ec16301a66a35361608af951ff71d43a3aa53dc (patch) | |
| tree | 7d81ae16a3badc54f5bcc024a5d59dc8ea6ceb64 /web/controller/util.go | |
| parent | 07245d614a21ebbc967b253e90e34d0664a7920f (diff) | |
Add X-Real-IP Support for Client IP (login page)
Diffstat (limited to 'web/controller/util.go')
| -rw-r--r-- | web/controller/util.go | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/web/controller/util.go b/web/controller/util.go index ac08f9af..17ad75e4 100644 --- a/web/controller/util.go +++ b/web/controller/util.go @@ -13,15 +13,18 @@ import ( ) func getRemoteIp(c *gin.Context) string { - value := c.GetHeader("X-Forwarded-For") + value := c.GetHeader("X-Real-IP") + if value != "" { + return value + } + value = c.GetHeader("X-Forwarded-For") if value != "" { ips := strings.Split(value, ",") return ips[0] - } else { - addr := c.Request.RemoteAddr - ip, _, _ := net.SplitHostPort(addr) - return ip } + addr := c.Request.RemoteAddr + ip, _, _ := net.SplitHostPort(addr) + return ip } func jsonMsg(c *gin.Context, msg string, err error) { |
