Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embed: use '*url.URL.Hostname(),Port()' for Go 1.8 #7766

Merged
merged 1 commit into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func (cfg *Config) UpdateDefaultClusterFromName(defaultInitialCluster string) (s
}

used := false
pip, pport, _ := net.SplitHostPort(cfg.LPUrls[0].Host)
pip, pport := cfg.LPUrls[0].Hostname(), cfg.LPUrls[0].Port()
if cfg.defaultPeerHost() && pip == "0.0.0.0" {
cfg.APUrls[0] = url.URL{Scheme: cfg.APUrls[0].Scheme, Host: fmt.Sprintf("%s:%s", defaultHostname, pport)}
used = true
Expand All @@ -397,7 +397,7 @@ func (cfg *Config) UpdateDefaultClusterFromName(defaultInitialCluster string) (s
cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name)
}

cip, cport, _ := net.SplitHostPort(cfg.LCUrls[0].Host)
cip, cport := cfg.LCUrls[0].Hostname(), cfg.LCUrls[0].Port()
if cfg.defaultClientHost() && cip == "0.0.0.0" {
cfg.ACUrls[0] = url.URL{Scheme: cfg.ACUrls[0].Scheme, Host: fmt.Sprintf("%s:%s", defaultHostname, cport)}
used = true
Expand Down
7 changes: 3 additions & 4 deletions embed/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package embed
import (
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
"testing"
Expand Down Expand Up @@ -74,7 +73,7 @@ func TestUpdateDefaultClusterFromName(t *testing.T) {
origadvc := cfg.ACUrls[0].String()

cfg.Name = "abc"
_, lpport, _ := net.SplitHostPort(cfg.LPUrls[0].Host)
lpport := cfg.LPUrls[0].Port()

// in case of 'etcd --name=abc'
exp := fmt.Sprintf("%s=%s://localhost:%s", cfg.Name, oldscheme, lpport)
Expand Down Expand Up @@ -105,13 +104,13 @@ func TestUpdateDefaultClusterFromNameOverwrite(t *testing.T) {
origadvc := cfg.ACUrls[0].String()

cfg.Name = "abc"
_, lpport, _ := net.SplitHostPort(cfg.LPUrls[0].Host)
lpport := cfg.LPUrls[0].Port()
cfg.LPUrls[0] = url.URL{Scheme: cfg.LPUrls[0].Scheme, Host: fmt.Sprintf("0.0.0.0:%s", lpport)}
dhost, _ := cfg.UpdateDefaultClusterFromName(defaultInitialCluster)
if dhost != defaultHostname {
t.Fatalf("expected default host %q, got %q", defaultHostname, dhost)
}
aphost, apport, _ := net.SplitHostPort(cfg.APUrls[0].Host)
aphost, apport := cfg.APUrls[0].Hostname(), cfg.APUrls[0].Port()
if apport != lpport {
t.Fatalf("advertise peer url got different port %s, expected %s", apport, lpport)
}
Expand Down