diff --git a/init.go b/init.go index e13e1fa..cb88e88 100644 --- a/init.go +++ b/init.go @@ -14,10 +14,13 @@ var ( File *file // Hash ... Hash *hash + // IP ... + IP *ip ) func init() { Cli = &cli{} File = &file{} Hash = &hash{} + IP = &ip{} } diff --git a/ip.go b/ip.go index 9ae7966..ae3f68d 100644 --- a/ip.go +++ b/ip.go @@ -12,12 +12,20 @@ import ( "net/http" ) +// ip ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:47 2022/5/14 +type ip struct { +} + // GetHostIP 获取本机IP地址 // // Author : go_developer@163.com<白茶清欢> // // Date : 5:58 下午 2021/3/9 -func GetHostIP() string { +func (i *ip) GetHostIP() string { hostIP := "127.0.0.1" addrs, _ := net.InterfaceAddrs() for _, address := range addrs { @@ -36,16 +44,14 @@ func GetHostIP() string { // Author : go_developer@163.com<白茶清欢> // // Date : 5:35 下午 2021/11/22 -func GetRemoteIp(req *http.Request) string { - +func (i *ip) GetRemoteIp(req *http.Request) string { // Try via request - - ip, _, err := net.SplitHostPort(req.RemoteAddr) + remoteIP, _, err := net.SplitHostPort(req.RemoteAddr) if err != nil { return "::1" } - userIP := net.ParseIP(ip) + userIP := net.ParseIP(remoteIP) if userIP == nil { return "::1" }