packageutilsimport("fmt""net")funcGetClientIp()(string,error){addrs,err:=net.InterfaceAddrs()iferr!=nil{return"",err}for_,address:=rangeaddrs{// 检查ip地址判断是否回环地址ifipNet,ok:=address.(*net.IPNet);ok&&ipNet.IP.IsGlobalUnicast(){//if ipNet, ok := address.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {ifipNet.IP.To4()!=nil{returnipNet.IP.String(),nil}}}return"",fmt.Errorf("can not find the client ip address")}