From 47766786dfc9ae1bf40cd5c4610b1318f75bfbb1 Mon Sep 17 00:00:00 2001 From: Vladimir Varankin Date: Fri, 13 Nov 2015 20:32:32 +0300 Subject: [PATCH] Simplify address formating Use `net.JoinHostPort()` which count IPv6 literals in `host`, instead of relying on `net.ParseIP(host).To4()` side effects. Signed-off-by: Vladimir Varankin --- parsers/parsers.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/parsers/parsers.go b/parsers/parsers.go index 453cccf..59fea5c 100644 --- a/parsers/parsers.go +++ b/parsers/parsers.go @@ -107,11 +107,7 @@ func ParseTCPAddr(tryAddr string, defaultAddr string) (string, error) { return "", fmt.Errorf("Invalid bind address format: %s", tryAddr) } - if net.ParseIP(host).To4() == nil && strings.Contains(host, ":") { - // This is either an ipv6 address - host = "[" + host + "]" - } - return fmt.Sprintf("tcp://%s:%d%s", host, p, u.Path), nil + return fmt.Sprintf("tcp://%s%s", net.JoinHostPort(host, port), u.Path), nil } // ParseRepositoryTag gets a repos name and returns the right reposName + tag|digest