mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-12-25 18:27:54 +08:00
26 lines
427 B
Go
26 lines
427 B
Go
|
package util
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
|
||
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||
|
)
|
||
|
|
||
|
func DetectedHostAddress() string {
|
||
|
addrs, err := net.InterfaceAddrs()
|
||
|
if err != nil {
|
||
|
glog.V(0).Infof("failed to detect ip address: %v", err)
|
||
|
return ""
|
||
|
}
|
||
|
|
||
|
for _, a := range addrs {
|
||
|
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||
|
if ipnet.IP.To4() != nil {
|
||
|
return ipnet.IP.String()
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return "localhost"
|
||
|
}
|