From 456343db6a6c9d2a1e78b46dac9b8e9f586fd15c Mon Sep 17 00:00:00 2001
From: "vito.he" <hxmhlt@163.com>
Date: Sun, 22 Mar 2020 18:23:20 +0800
Subject: [PATCH] Mod:enhance url init code

---
 common/constant/key.go              | 1 +
 config/reference_config.go          | 4 ++++
 config/service_config.go            | 4 ++++
 registry/base_registry.go           | 9 ---------
 registry/etcdv3/registry_test.go    | 2 +-
 registry/zookeeper/registry_test.go | 2 +-
 6 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/common/constant/key.go b/common/constant/key.go
index 07335bed5..488da4867 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -41,6 +41,7 @@ const (
 	LOCAL_ADDR             = "local-addr"
 	REMOTE_ADDR            = "remote-addr"
 	PATH_SEPARATOR         = "/"
+	DUBBO_KEY              = "dubbo"
 )
 
 const (
diff --git a/config/reference_config.go b/config/reference_config.go
index 7ce001319..6fe8b02f5 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -185,6 +185,10 @@ func (c *ReferenceConfig) getUrlMap() url.Values {
 	urlMap.Set(constant.VERSION_KEY, c.Version)
 	urlMap.Set(constant.GENERIC_KEY, strconv.FormatBool(c.Generic))
 	urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))
+	urlMap.Set(constant.CATEGORY_KEY, (common.RoleType(common.CONSUMER)).String())
+	urlMap.Set(constant.DUBBO_KEY, "dubbo-consumer-golang-"+constant.Version)
+	urlMap.Set(constant.SIDE_KEY, (common.RoleType(common.CONSUMER)).Role())
+
 	if len(c.RequestTimeout) != 0 {
 		urlMap.Set(constant.TIMEOUT_KEY, c.RequestTimeout)
 	}
diff --git a/config/service_config.go b/config/service_config.go
index 7d97fa4d1..3624804db 100644
--- a/config/service_config.go
+++ b/config/service_config.go
@@ -193,6 +193,10 @@ func (c *ServiceConfig) getUrlMap() url.Values {
 	urlMap.Set(constant.GROUP_KEY, c.Group)
 	urlMap.Set(constant.VERSION_KEY, c.Version)
 	urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
+	urlMap.Set(constant.CATEGORY_KEY, (common.RoleType(common.PROVIDER)).String())
+	urlMap.Set(constant.DUBBO_KEY, "dubbo-provider-golang-"+constant.Version)
+	urlMap.Set(constant.SIDE_KEY, (common.RoleType(common.PROVIDER)).Role())
+
 	// application info
 	urlMap.Set(constant.APPLICATION_KEY, providerConfig.ApplicationConfig.Name)
 	urlMap.Set(constant.ORGANIZATION_KEY, providerConfig.ApplicationConfig.Organization)
diff --git a/registry/base_registry.go b/registry/base_registry.go
index 3b64e93e2..18ec608ca 100644
--- a/registry/base_registry.go
+++ b/registry/base_registry.go
@@ -249,12 +249,6 @@ func (r *BaseRegistry) providerRegistry(c common.URL, params url.Values) (string
 
 	// Dubbo java consumer to start looking for the provider url,because the category does not match,
 	// the provider will not find, causing the consumer can not start, so we use consumers.
-	// DubboRole               = [...]string{"consumer", "", "", "provider"}
-	// params.Add("category", (RoleType(PROVIDER)).Role())
-	params.Add("category", (common.RoleType(common.PROVIDER)).String())
-	params.Add("dubbo", "dubbo-provider-golang-"+constant.Version)
-
-	params.Add("side", (common.RoleType(common.PROVIDER)).Role())
 
 	if len(c.Methods) == 0 {
 		params.Add("methods", strings.Join(c.Methods, ","))
@@ -308,9 +302,6 @@ func (r *BaseRegistry) consumerRegistry(c common.URL, params url.Values) (string
 	}
 
 	params.Add("protocol", c.Protocol)
-	params.Add("category", (common.RoleType(common.CONSUMER)).String())
-	params.Add("dubbo", "dubbogo-consumer-"+constant.Version)
-
 	rawURL = fmt.Sprintf("consumer://%s%s?%s", localIP, c.Path, params.Encode())
 	dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), (common.RoleType(common.CONSUMER)).String())
 
diff --git a/registry/etcdv3/registry_test.go b/registry/etcdv3/registry_test.go
index 6e26a8f3f..51644be85 100644
--- a/registry/etcdv3/registry_test.go
+++ b/registry/etcdv3/registry_test.go
@@ -63,7 +63,7 @@ func (suite *RegistryTestSuite) TestRegister() {
 	if err != nil {
 		t.Fatal(err)
 	}
-	assert.Regexp(t, ".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26category%3Dproviders%26cluster%3Dmock%26dubbo%3Ddubbo-provider-golang-1.3.0%26.*provider", children)
+	assert.Regexp(t, ".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26cluster%3Dmock", children)
 	assert.NoError(t, err)
 }
 
diff --git a/registry/zookeeper/registry_test.go b/registry/zookeeper/registry_test.go
index 0d7623ca1..688deccfb 100644
--- a/registry/zookeeper/registry_test.go
+++ b/registry/zookeeper/registry_test.go
@@ -41,7 +41,7 @@ func Test_Register(t *testing.T) {
 	defer ts.Stop()
 	err := reg.Register(url)
 	children, _ := reg.client.GetChildren("/dubbo/com.ikurento.user.UserProvider/providers")
-	assert.Regexp(t, ".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26category%3Dproviders%26cluster%3Dmock%26dubbo%3Ddubbo-provider-golang-1.3.0%26.*.serviceid%3Dsoa.mock%26.*provider", children)
+	assert.Regexp(t, ".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26cluster%3Dmock%26.*.serviceid%3Dsoa.mock", children)
 	assert.NoError(t, err)
 }
 
-- 
GitLab