You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by jo...@apache.org on 2020/03/10 07:23:50 UTC

[dubbo-go] branch feature/rest updated: modify rest

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

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


The following commit(s) were added to refs/heads/feature/rest by this push:
     new 1fd0ddb  modify rest
     new 73119b4  Merge pull request #396 from Patrick0308/rest
1fd0ddb is described below

commit 1fd0ddb6c14b08e2313ebe5152115406f19aa773
Author: Patrick <dr...@foxmail.com>
AuthorDate: Tue Mar 10 15:05:50 2020 +0800

    modify rest
---
 protocol/rest/rest_protocol.go | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/protocol/rest/rest_protocol.go b/protocol/rest/rest_protocol.go
index f4f12e4..fe147e2 100644
--- a/protocol/rest/rest_protocol.go
+++ b/protocol/rest/rest_protocol.go
@@ -55,8 +55,8 @@ type RestProtocol struct {
 func NewRestProtocol() *RestProtocol {
 	return &RestProtocol{
 		BaseProtocol: protocol.NewBaseProtocol(),
-		serverMap:    make(map[string]rest_interface.RestServer),
-		clientMap:    make(map[rest_interface.RestOptions]rest_interface.RestClient),
+		serverMap:    make(map[string]rest_interface.RestServer, 8),
+		clientMap:    make(map[rest_interface.RestOptions]rest_interface.RestClient, 8),
 	}
 }
 
@@ -105,13 +105,13 @@ func (rp *RestProtocol) getServer(url common.URL, serverType string) rest_interf
 		panic("[RestProtocol]" + url.ServiceKey() + "is not existing")
 	}
 	rp.serverLock.Lock()
+	defer rp.serverLock.Unlock()
 	restServer, ok = rp.serverMap[url.Location]
 	if !ok {
 		restServer = extension.GetNewRestServer(serverType)
 		restServer.Start(url)
 		rp.serverMap[url.Location] = restServer
 	}
-	rp.serverLock.Unlock()
 	return restServer
 }
 
@@ -121,12 +121,12 @@ func (rp *RestProtocol) getClient(restOptions rest_interface.RestOptions, client
 		return restClient
 	}
 	rp.clientLock.Lock()
+	defer rp.clientLock.Unlock()
 	restClient, ok = rp.clientMap[restOptions]
 	if !ok {
 		restClient = extension.GetNewRestClient(clientType, &restOptions)
 		rp.clientMap[restOptions] = restClient
 	}
-	rp.clientLock.Unlock()
 	return restClient
 }