mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #12469 from trawler/client_listen_unix_socket
pkg/types: Support Unix sockets in NewURLS
This commit is contained in:
commit
b2726c4da3
@ -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
|
||||
}
|
||||
|
||||
|
@ -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#$",
|
||||
@ -56,6 +53,9 @@ func TestNewURLsValue(t *testing.T) {
|
||||
{s: "http://10.1.1.1:80", exp: []url.URL{{Scheme: "http", Host: "10.1.1.1:80"}}},
|
||||
{s: "http://localhost:80", exp: []url.URL{{Scheme: "http", Host: "localhost:80"}}},
|
||||
{s: "http://:80", exp: []url.URL{{Scheme: "http", Host: ":80"}}},
|
||||
{s: "unix://tmp/etcd.sock", exp: []url.URL{{Scheme: "unix", Host: "tmp", Path: "/etcd.sock"}}},
|
||||
{s: "unix:///tmp/127.27.84.4:23432", exp: []url.URL{{Scheme: "unix", Path: "/tmp/127.27.84.4:23432"}}},
|
||||
{s: "unix://127.0.0.5:1456", exp: []url.URL{{Scheme: "unix", Host: "127.0.0.5:1456"}}},
|
||||
{
|
||||
s: "http://localhost:1,https://localhost:2",
|
||||
exp: []url.URL{
|
||||
|
Loading…
x
Reference in New Issue
Block a user