From 59569dbd6794052afaf84ca5ffa67140f8f13c75 Mon Sep 17 00:00:00 2001 From: John Hopper Date: Fri, 12 Aug 2022 09:05:37 -0700 Subject: [PATCH] fix: patch up URL handling for addresses to support port specification --- cmd/utils.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/utils.go b/cmd/utils.go index c1ff32d..4f135a4 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -100,12 +100,20 @@ func dial(targetUrl string) (string, error) { log.V(2).Info("dialing...", "targetUrl", targetUrl) if url, err := url.Parse(targetUrl); err != nil { return "", err - } else if conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:https", url.Host), 5*time.Second); err != nil { - return "", err } else { - defer conn.Close() - addr := conn.LocalAddr().(*net.TCPAddr) - return addr.IP.String(), nil + port := url.Port() + + if port == "" { + port = "https" + } + + if conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%s", url.Hostname(), port), 5*time.Second); err != nil { + return "", err + } else { + defer conn.Close() + addr := conn.LocalAddr().(*net.TCPAddr) + return addr.IP.String(), nil + } } }