You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
540 B
27 lines
540 B
4 years ago
|
package utils
|
||
|
|
||
|
import (
|
||
3 years ago
|
"Open_IM/pkg/common/config"
|
||
4 years ago
|
"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
|
||
|
}
|
||
3 years ago
|
|
||
|
// see https://gist.github.com/jniltinho/9787946#gistcomment-3019898
|
||
|
conn, err := net.Dial("udp", "8.8.8.8:80")
|
||
4 years ago
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
3 years ago
|
|
||
|
defer conn.Close()
|
||
|
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
||
|
ServerIP = localAddr.IP.String()
|
||
4 years ago
|
}
|