1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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 <nek.narqo@gmail.com>
This commit is contained in:
Vladimir Varankin 2015-11-13 20:32:32 +03:00
parent 02bc514fb8
commit 3830359745

View file

@ -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