mv src/common src/utils src/grpc-etcdv3 to pkg

This commit is contained in:
xmcy0011
2021-10-11 22:12:01 +08:00
parent bc94d4e0b3
commit 737edb985b
119 changed files with 310 additions and 702 deletions
+35
View File
@@ -0,0 +1,35 @@
package utils
import (
"Open_IM/pkg/common/config"
"net"
)
var ServerIP = ""
func init() {
//fixme In the configuration file, ip takes precedence, if not, get the valid network card ip of the machine
if config.Config.ServerIP != "" {
ServerIP = config.Config.ServerIP
return
}
//fixme Get the ip of the local network card
netInterfaces, err := net.Interfaces()
if err != nil {
panic(err)
}
for i := 0; i < len(netInterfaces); i++ {
//Exclude useless network cards by judging the net.flag Up flag
if (netInterfaces[i].Flags & net.FlagUp) != 0 {
address, _ := netInterfaces[i].Addrs()
for _, addr := range address {
if ipNet, ok := addr.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
if ipNet.IP.To4() != nil {
ServerIP = ipNet.IP.String()
return
}
}
}
}
}
}