diff --git a/client/pkg/types/urls.go b/client/pkg/types/urls.go index 9e5d03ff6..49a38967e 100644 --- a/client/pkg/types/urls.go +++ b/client/pkg/types/urls.go @@ -36,20 +36,25 @@ func NewURLs(strs []string) (URLs, error) { if err != nil { return nil, err } - if u.Scheme != "http" && u.Scheme != "https" && u.Scheme != "unix" && u.Scheme != "unixs" { + + switch u.Scheme { + case "http", "https": + if _, _, err := net.SplitHostPort(u.Host); err != nil { + return nil, fmt.Errorf(`URL address does not have the form "host:port": %s`, in) + } + + if u.Path != "" { + return nil, fmt.Errorf("URL must not contain a path: %s", in) + } + case "unix", "unixs": + break + default: return nil, fmt.Errorf("URL scheme must be http, https, unix, or unixs: %s", in) } - if _, _, err := net.SplitHostPort(u.Host); err != nil { - return nil, fmt.Errorf(`URL address does not have the form "host:port": %s`, in) - } - if u.Path != "" { - return nil, fmt.Errorf("URL must not contain a path: %s", in) - } all[i] = *u } us := URLs(all) us.Sort() - return us, nil } diff --git a/pkg/flags/urls_test.go b/pkg/flags/urls_test.go index ff4bda8d4..75c2f6414 100644 --- a/pkg/flags/urls_test.go +++ b/pkg/flags/urls_test.go @@ -29,9 +29,6 @@ func TestValidateURLsValueBad(t *testing.T) { // bad port specification "127.0.0.1:foo", "127.0.0.1:", - // unix sockets not supported - "unix://", - "unix://tmp/etcd.sock", // bad strings "somewhere", "234#$",