1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-03-17 21:07:54 +02:00

judge if interface is up (#256)

This commit is contained in:
wuxingzhong 2019-08-14 09:04:41 +08:00 committed by Felix Hao
parent 38fc6590d5
commit 3e92753a1b

View File

@ -48,6 +48,9 @@ func InternalIP() string {
return ""
}
for _, inter := range inters {
if !isUp(inter.Flags) {
continue
}
if !strings.HasPrefix(inter.Name, "lo") {
addrs, err := inter.Addrs()
if err != nil {
@ -64,3 +67,8 @@ func InternalIP() string {
}
return ""
}
// isUp Interface is up
func isUp(v net.Flags) bool {
return v&net.FlagUp == net.FlagUp
}