This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch 1.5
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/1.5 by this push:
     new 060e273  fix: support multi address (#1306) (#1671)
060e273 is described below

commit 060e2730fb3ebdbceca75c4326f2bf64003bd8b4
Author: LeonXu <[email protected]>
AuthorDate: Sat Dec 18 15:52:07 2021 +0800

    fix: support multi address (#1306) (#1671)
---
 common/url.go | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/common/url.go b/common/url.go
index 18d0a1e..e51fd70 100644
--- a/common/url.go
+++ b/common/url.go
@@ -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 {

Reply via email to