From bd8323b1c61a2b0592cfb7c53a73b359a7546230 Mon Sep 17 00:00:00 2001
From: "vito.he" <hxmhlt@163.com>
Date: Tue, 10 Sep 2019 21:00:03 +0800
Subject: [PATCH] Add:retries mergeUrl

---
 common/url.go      | 35 ++++++++++++++++-------------------
 common/url_test.go |  3 +++
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/common/url.go b/common/url.go
index 6431ee129..c00017fc9 100644
--- a/common/url.go
+++ b/common/url.go
@@ -427,25 +427,8 @@ func MergeUrl(serviceUrl URL, referenceUrl *URL) URL {
 			mergedUrl.Params.Set(k, v[0])
 		}
 	}
-	//loadBalance strategy config
-	if v := referenceUrl.Params.Get(constant.LOADBALANCE_KEY); v != "" {
-		mergedUrl.Params.Set(constant.LOADBALANCE_KEY, v)
-	}
-	methodConfigMergeFcn = append(methodConfigMergeFcn, func(method string) {
-		if v := referenceUrl.Params.Get(method + "." + constant.LOADBALANCE_KEY); v != "" {
-			mergedUrl.Params.Set(method+"."+constant.LOADBALANCE_KEY, v)
-		}
-	})
-
-	//cluster strategy config
-	if v := referenceUrl.Params.Get(constant.CLUSTER_KEY); v != "" {
-		mergedUrl.Params.Set(constant.CLUSTER_KEY, v)
-	}
-	methodConfigMergeFcn = append(methodConfigMergeFcn, func(method string) {
-		if v := referenceUrl.Params.Get(method + "." + constant.CLUSTER_KEY); v != "" {
-			mergedUrl.Params.Set(method+"."+constant.CLUSTER_KEY, v)
-		}
-	})
+	//loadBalance,cluster,retries strategy config
+	mergeNormalParam(mergedUrl, referenceUrl, methodConfigMergeFcn, []string{constant.LOADBALANCE_KEY, constant.CLUSTER_KEY, constant.RETRIES_KEY})
 
 	//remote timestamp
 	if v := serviceUrl.Params.Get(constant.TIMESTAMP_KEY); v != "" {
@@ -462,3 +445,17 @@ func MergeUrl(serviceUrl URL, referenceUrl *URL) URL {
 
 	return mergedUrl
 }
+
+func mergeNormalParam(mergedUrl URL, referenceUrl *URL, methodConfigMergeFcn []func(method string), paramKeys []string) {
+	for _, paramKey := range paramKeys {
+		if v := referenceUrl.Params.Get(paramKey); v != "" {
+			mergedUrl.Params.Set(paramKey, v)
+		}
+		methodConfigMergeFcn = append(methodConfigMergeFcn, func(method string) {
+			if v := referenceUrl.Params.Get(method + "." + paramKey); v != "" {
+				mergedUrl.Params.Set(method+"."+paramKey, v)
+			}
+		})
+	}
+
+}
diff --git a/common/url_test.go b/common/url_test.go
index 143e31cb3..6cd653fc9 100644
--- a/common/url_test.go
+++ b/common/url_test.go
@@ -220,10 +220,12 @@ func TestURL_GetMethodParam(t *testing.T) {
 func TestMergeUrl(t *testing.T) {
 	referenceUrlParams := url.Values{}
 	referenceUrlParams.Set(constant.CLUSTER_KEY, "random")
+	referenceUrlParams.Set(constant.RETRIES_KEY, "1")
 	referenceUrlParams.Set("test3", "1")
 	serviceUrlParams := url.Values{}
 	serviceUrlParams.Set("test2", "1")
 	serviceUrlParams.Set(constant.CLUSTER_KEY, "roundrobin")
+	serviceUrlParams.Set(constant.RETRIES_KEY, "2")
 	referenceUrl, _ := NewURL(context.TODO(), "mock1://127.0.0.1:1111", WithParams(referenceUrlParams))
 	serviceUrl, _ := NewURL(context.TODO(), "mock2://127.0.0.1:20000", WithParams(serviceUrlParams))
 
@@ -231,4 +233,5 @@ func TestMergeUrl(t *testing.T) {
 	assert.Equal(t, "random", mergedUrl.GetParam(constant.CLUSTER_KEY, ""))
 	assert.Equal(t, "1", mergedUrl.GetParam("test2", ""))
 	assert.Equal(t, "1", mergedUrl.GetParam("test3", ""))
+	assert.Equal(t, "1", mergedUrl.GetParam(constant.RETRIES_KEY, ""))
 }
-- 
GitLab