Update host.go (#2013)

status-code-override
songzhibin97 3 years ago committed by chenzhihui
parent 769a40957c
commit 291f0f3ad0
  1. 12
      internal/host/host.go

@ -14,9 +14,6 @@ func ExtractHostPort(addr string) (host string, port uint64, err error) {
return return
} }
port, err = strconv.ParseUint(ports, 10, 16) //nolint:gomnd port, err = strconv.ParseUint(ports, 10, 16) //nolint:gomnd
if err != nil {
return
}
return return
} }
@ -40,11 +37,11 @@ func Extract(hostPort string, lis net.Listener) (string, error) {
return "", err return "", err
} }
if lis != nil { if lis != nil {
if p, ok := Port(lis); ok { p, ok := Port(lis)
port = strconv.Itoa(p) if !ok {
} else {
return "", fmt.Errorf("failed to extract port: %v", lis.Addr()) return "", fmt.Errorf("failed to extract port: %v", lis.Addr())
} }
port = strconv.Itoa(p)
} }
if len(addr) > 0 && (addr != "0.0.0.0" && addr != "[::]" && addr != "::") { if len(addr) > 0 && (addr != "0.0.0.0" && addr != "[::]" && addr != "::") {
return net.JoinHostPort(addr, port), nil return net.JoinHostPort(addr, port), nil
@ -61,7 +58,8 @@ func Extract(hostPort string, lis net.Listener) (string, error) {
} }
if iface.Index < lowest || result == nil { if iface.Index < lowest || result == nil {
lowest = iface.Index lowest = iface.Index
} else if result != nil { }
if result != nil {
continue continue
} }
addrs, err := iface.Addrs() addrs, err := iface.Addrs()

Loading…
Cancel
Save