diff --git a/parsers/parsers.go b/parsers/parsers.go index a604a9e..453cccf 100644 --- a/parsers/parsers.go +++ b/parsers/parsers.go @@ -74,6 +74,18 @@ func ParseTCPAddr(tryAddr string, defaultAddr string) (string, error) { return "", fmt.Errorf("Invalid proto, expected tcp: %s", tryAddr) } + defaultAddr = strings.TrimPrefix(defaultAddr, "tcp://") + defaultHost, defaultPort, err := net.SplitHostPort(defaultAddr) + if err != nil { + return "", err + } + // url.Parse fails for trailing colon on IPv6 brackets on Go 1.5, but + // not 1.4. See https://github.com/golang/go/issues/12200 and + // https://github.com/golang/go/issues/6530. + if strings.HasSuffix(addr, "]:") { + addr += defaultPort + } + u, err := url.Parse("tcp://" + addr) if err != nil { return "", err @@ -84,12 +96,6 @@ func ParseTCPAddr(tryAddr string, defaultAddr string) (string, error) { return "", fmt.Errorf("Invalid bind address format: %s", tryAddr) } - defaultAddr = strings.TrimPrefix(defaultAddr, "tcp://") - defaultHost, defaultPort, err := net.SplitHostPort(defaultAddr) - if err != nil { - return "", err - } - if host == "" { host = defaultHost }