From b3ce41b3b021313005f160f5ed58d2f3491786b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 1 Jul 2022 16:16:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=81=E9=87=8A=E6=94=BE?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rpc.go b/rpc.go index a5ca01e..c7de2c9 100644 --- a/rpc.go +++ b/rpc.go @@ -105,7 +105,7 @@ func (r *request) GetServiceInfo(serviceFlag string) (*Service, error) { ) r.lock.RLock() - defer r.lock.Unlock() + defer r.lock.RUnlock() if serviceInfo, exist = r.serviceTable[serviceFlag]; !exist { return nil, errors.New(serviceFlag + " -> 服务不存在") } @@ -176,8 +176,8 @@ func (r *request) GetServiceApi(serviceFlag string, apiFlag string) (*Service, * if serviceInfo, err = r.GetServiceInfo(serviceFlag); nil != err { return nil, nil, err } - r.lock.Lock() - defer r.lock.Unlock() + r.lock.RLock() + defer r.lock.RUnlock() if apiInfo, exist = serviceInfo.ApiTable[apiFlag]; !exist { return nil, nil, errors.New(serviceFlag + " : " + apiFlag + " -> api") } @@ -311,6 +311,9 @@ func (r *request) getFullURLAndBody(serviceConfig *Service, apiConfig *Api, para case http.MethodDelete: body, _ = json.Marshal(parameter) } + if nil == body { + body = []byte("{}") + } query := strings.Join(parameterPair, "&") if len(query) == 0 { return strings.ReplaceAll(fullURL, "//", "/"), body