diff --git a/conn.go b/conn.go index bbed31f9..97377ece 100644 --- a/conn.go +++ b/conn.go @@ -17,7 +17,6 @@ import ( "fmt" "io" "net" - "strconv" "strings" "sync" "sync/atomic" @@ -180,15 +179,7 @@ func Connect(servers []string, sessionTimeout time.Duration, options ...connOpti return nil, nil, errors.New("zk: server list must not be empty") } - srvs := make([]string, len(servers)) - - for i, addr := range servers { - if strings.Contains(addr, ":") { - srvs[i] = addr - } else { - srvs[i] = addr + ":" + strconv.Itoa(DefaultPort) - } - } + srvs := FormatServers(servers) // Randomize the order of the servers to avoid creating hotspots stringShuffle(srvs) diff --git a/util.go b/util.go index f40a5b15..5a92b66b 100644 --- a/util.go +++ b/util.go @@ -38,12 +38,15 @@ func DigestACL(perms int32, user, password string) []ACL { // that resembles :. If the server has no port provided, the // DefaultPort constant is added to the end. func FormatServers(servers []string) []string { - for i := range servers { - if !strings.Contains(servers[i], ":") { - servers[i] = servers[i] + ":" + strconv.Itoa(DefaultPort) + srvs := make([]string, len(servers)) + for i, addr := range servers { + if strings.Contains(addr, ":") { + srvs[i] = addr + } else { + srvs[i] = addr + ":" + strconv.Itoa(DefaultPort) } } - return servers + return srvs } // stringShuffle performs a Fisher-Yates shuffle on a slice of strings