feature/balance #3

Merged
zhangdeman merged 7 commits from feature/balance into master 2021-11-22 19:13:50 +08:00
Showing only changes of commit 42282e2001 - Show all commits

View File

@ -7,7 +7,10 @@
// Date : 2021-03-09 5:56 下午 // Date : 2021-03-09 5:56 下午
package util package util
import "net" import (
"net"
"net/http"
)
// GetHostIP 获取本机IP地址 // GetHostIP 获取本机IP地址
// //
@ -27,3 +30,24 @@ func GetHostIP() string {
} }
return hostIP return hostIP
} }
// GetRemoteIp 获取远端IP
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 5:35 下午 2021/11/22
func GetRemoteIp(req *http.Request) string {
// Try via request
ip, _, err := net.SplitHostPort(req.RemoteAddr)
if err != nil {
return "::1"
}
userIP := net.ParseIP(ip)
if userIP == nil {
return "::1"
}
return userIP.String()
}