修复锁释放错误问题

This commit is contained in:
白茶清欢 2022-07-01 16:16:58 +08:00
parent ce8f34cc81
commit b3ce41b3b0

9
rpc.go
View File

@ -105,7 +105,7 @@ func (r *request) GetServiceInfo(serviceFlag string) (*Service, error) {
) )
r.lock.RLock() r.lock.RLock()
defer r.lock.Unlock() defer r.lock.RUnlock()
if serviceInfo, exist = r.serviceTable[serviceFlag]; !exist { if serviceInfo, exist = r.serviceTable[serviceFlag]; !exist {
return nil, errors.New(serviceFlag + " -> 服务不存在") 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 { if serviceInfo, err = r.GetServiceInfo(serviceFlag); nil != err {
return nil, nil, err return nil, nil, err
} }
r.lock.Lock() r.lock.RLock()
defer r.lock.Unlock() defer r.lock.RUnlock()
if apiInfo, exist = serviceInfo.ApiTable[apiFlag]; !exist { if apiInfo, exist = serviceInfo.ApiTable[apiFlag]; !exist {
return nil, nil, errors.New(serviceFlag + " : " + apiFlag + " -> api") return nil, nil, errors.New(serviceFlag + " : " + apiFlag + " -> api")
} }
@ -311,6 +311,9 @@ func (r *request) getFullURLAndBody(serviceConfig *Service, apiConfig *Api, para
case http.MethodDelete: case http.MethodDelete:
body, _ = json.Marshal(parameter) body, _ = json.Marshal(parameter)
} }
if nil == body {
body = []byte("{}")
}
query := strings.Join(parameterPair, "&") query := strings.Join(parameterPair, "&")
if len(query) == 0 { if len(query) == 0 {
return strings.ReplaceAll(fullURL, "//", "/"), body return strings.ReplaceAll(fullURL, "//", "/"), body