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

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


The following commit(s) were added to refs/heads/develop by this push:
     new c0839f0  support zkpath urlencoder
     new 5a50da7  Merge pull request #283 from xujianhai666/feat-urlencoder
c0839f0 is described below

commit c0839f0a6233da78e4161150d5c6e2c62868a9cc
Author: xujianhai666 <[email protected]>
AuthorDate: Tue Dec 17 10:19:37 2019 +0800

    support zkpath urlencoder
---
 registry/zookeeper/registry.go      | 16 ++++++++++------
 remoting/zookeeper/listener_test.go |  7 +++++++
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go
index e419915..1defedc 100644
--- a/registry/zookeeper/registry.go
+++ b/registry/zookeeper/registry.go
@@ -261,6 +261,10 @@ func (r *zkRegistry) Register(conf common.URL) error {
        return nil
 }
 
+func (r *zkRegistry) service(c common.URL) string {
+       return url.QueryEscape(c.Service())
+}
+
 func (r *zkRegistry) register(c common.URL) error {
        var (
                err error
@@ -296,7 +300,7 @@ func (r *zkRegistry) register(c common.URL) error {
                        return perrors.Errorf("conf{Path:%s, Methods:%s}", 
c.Path, c.Methods)
                }
                // 先创建服务下面的provider node
-               dubboPath = fmt.Sprintf("/dubbo/%s/%s", c.Service(), 
common.DubboNodes[common.PROVIDER])
+               dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), 
common.DubboNodes[common.PROVIDER])
                r.cltLock.Lock()
                err = r.client.Create(dubboPath)
                r.cltLock.Unlock()
@@ -330,11 +334,11 @@ func (r *zkRegistry) register(c common.URL) error {
                encodedURL = url.QueryEscape(rawURL)
 
                // Print your own registration service providers.
-               dubboPath = fmt.Sprintf("/dubbo/%s/%s", c.Service(), 
(common.RoleType(common.PROVIDER)).String())
+               dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), 
(common.RoleType(common.PROVIDER)).String())
                logger.Debugf("provider path:%s, url:%s", dubboPath, rawURL)
 
        case common.CONSUMER:
-               dubboPath = fmt.Sprintf("/dubbo/%s/%s", c.Service(), 
common.DubboNodes[common.CONSUMER])
+               dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), 
common.DubboNodes[common.CONSUMER])
                r.cltLock.Lock()
                err = r.client.Create(dubboPath)
                r.cltLock.Unlock()
@@ -342,7 +346,7 @@ func (r *zkRegistry) register(c common.URL) error {
                        logger.Errorf("zkClient.create(path{%s}) = error{%v}", 
dubboPath, perrors.WithStack(err))
                        return perrors.WithStack(err)
                }
-               dubboPath = fmt.Sprintf("/dubbo/%s/%s", c.Service(), 
common.DubboNodes[common.PROVIDER])
+               dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), 
common.DubboNodes[common.PROVIDER])
                r.cltLock.Lock()
                err = r.client.Create(dubboPath)
                r.cltLock.Unlock()
@@ -359,7 +363,7 @@ func (r *zkRegistry) register(c common.URL) error {
                rawURL = fmt.Sprintf("consumer://%s%s?%s", localIP, c.Path, 
params.Encode())
                encodedURL = url.QueryEscape(rawURL)
 
-               dubboPath = fmt.Sprintf("/dubbo/%s/%s", c.Service(), 
(common.RoleType(common.CONSUMER)).String())
+               dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), 
(common.RoleType(common.CONSUMER)).String())
                logger.Debugf("consumer path:%s, url:%s", dubboPath, rawURL)
 
        default:
@@ -479,7 +483,7 @@ func (r *zkRegistry) getListener(conf *common.URL) 
(*RegistryConfigurationListen
        //Interested register to dataconfig.
        r.dataListener.AddInterestedURL(conf)
        for _, v := range strings.Split(conf.GetParam(constant.CATEGORY_KEY, 
constant.DEFAULT_CATEGORY), ",") {
-               go r.listener.ListenServiceEvent(fmt.Sprintf("/dubbo/%s/"+v, 
conf.Service()), r.dataListener)
+               go r.listener.ListenServiceEvent(fmt.Sprintf("/dubbo/%s/"+v, 
url.QueryEscape(conf.Service())), r.dataListener)
        }
 
        return zkListener, nil
diff --git a/remoting/zookeeper/listener_test.go 
b/remoting/zookeeper/listener_test.go
index a90fbad..aa627c7 100644
--- a/remoting/zookeeper/listener_test.go
+++ b/remoting/zookeeper/listener_test.go
@@ -18,6 +18,7 @@
 package zookeeper
 
 import (
+       "net/url"
        "sync"
        "testing"
        "time"
@@ -122,3 +123,9 @@ func (m *mockDataListener) DataChange(eventType 
remoting.Event) bool {
        }
        return true
 }
+
+func TestZkPath(t *testing.T) {
+       zkPath := "io.grpc.examples.helloworld.GreeterGrpc$IGreeter"
+       zkPath = url.QueryEscape(zkPath)
+       assert.Equal(t, zkPath, 
"io.grpc.examples.helloworld.GreeterGrpc%24IGreeter")
+}

Reply via email to