From 291f0f3ad0a4dca7495241ca626fbb58296200b0 Mon Sep 17 00:00:00 2001 From: songzhibin97 <49082129+songzhibin97@users.noreply.github.com> Date: Fri, 20 May 2022 22:36:18 +0800 Subject: [PATCH] Update host.go (#2013) --- internal/host/host.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/host/host.go b/internal/host/host.go index 078660be5..d5cc7ffa3 100644 --- a/internal/host/host.go +++ b/internal/host/host.go @@ -14,9 +14,6 @@ func ExtractHostPort(addr string) (host string, port uint64, err error) { return } port, err = strconv.ParseUint(ports, 10, 16) //nolint:gomnd - if err != nil { - return - } return } @@ -40,11 +37,11 @@ func Extract(hostPort string, lis net.Listener) (string, error) { return "", err } if lis != nil { - if p, ok := Port(lis); ok { - port = strconv.Itoa(p) - } else { + p, ok := Port(lis) + if !ok { 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 != "::") { 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 { lowest = iface.Index - } else if result != nil { + } + if result != nil { continue } addrs, err := iface.Addrs()