Skip to content

Commit

Permalink
feat: optimize buildPath code
Browse files Browse the repository at this point in the history
  • Loading branch information
zstone12 authored and Haswf committed Aug 28, 2022
1 parent 03819c8 commit 94c1525
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions zookeeper/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,18 @@ func buildPath(info *registry.Info) (string, error) {
if !strings.HasPrefix(info.ServiceName, Separator) {
path = Separator + info.ServiceName
}

if host, port, err := net.SplitHostPort(info.Addr.String()); err == nil {
if port == "" {
return "", fmt.Errorf("registry info addr missing port")
}
if host == "" || host == "::" {
host = utils.LocalIP()
path = path + Separator + "[" + host + "]" + ":" + port
} else {
path = path + Separator + host + ":" + port
}
} else {
host, port, err := net.SplitHostPort(info.Addr.String())
if err != nil {
return "", fmt.Errorf("parse registry info addr error")
}
if port == "" {
return "", fmt.Errorf("registry info addr missing port")
}
if host == "" || host == "::" {
host = utils.LocalIP()
}
path = path + Separator + net.JoinHostPort(host, port)

return path, nil
}

Expand Down

0 comments on commit 94c1525

Please # to comment.