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