Skip to content

Commit

Permalink
fix: support multi address (apache#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
xfstart07 committed Dec 16, 2021
1 parent 9b86b2d commit be44043
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,14 @@ func NewURL(urlString string, opts ...Option) (*URL, error) {
s.Password, _ = serviceUrl.User.Password()
s.Location = serviceUrl.Host
s.Path = serviceUrl.Path
if strings.Contains(s.Location, ":") {
s.Ip, s.Port, err = net.SplitHostPort(s.Location)
if err != nil {
return &s, perrors.Errorf("net.SplitHostPort(url.Host{%s}), error{%v}", s.Location, err)
for _, location := range strings.Split(s.Location, ",") {
location = strings.Trim(location, " ")
if strings.Contains(location, ":") {
s.Ip, s.Port, err = net.SplitHostPort(location)
if err != nil {
return &s, perrors.Errorf("net.SplitHostPort(url.Host{%s}), error{%v}", s.Location, err)
}
break
}
}
for _, opt := range opts {
Expand Down

0 comments on commit be44043

Please sign in to comment.