修复日志记录BUG + 优化请求参数处理

This commit is contained in:
白茶清欢 2022-07-02 13:42:35 +08:00
parent 6916755206
commit f80576d8a8

18
rpc.go
View File

@ -68,7 +68,8 @@ func InitRPCFromCfgDir(cfgDir string, logger *zap.Logger) error {
serviceInfo Service
err error
)
if err = util.File.ReadJSONContent(cfgDir+string(filepath.Separator)+filepathNames[i], &serviceInfo); nil != err {
if err = util.File.ReadAnyFileContent(filepathNames[i], &serviceInfo); nil != err {
return err
}
serviceTable[serviceInfo.Flag] = &serviceInfo
@ -86,7 +87,7 @@ func InitRPCFromCfgFile(cfgFile string, logger *zap.Logger) error {
serviceTable map[string]*Service
err error
)
if err = util.File.ReadJSONContent(cfgFile, &serviceTable); nil != err {
if err = util.File.ReadAnyFileContent(cfgFile, &serviceTable); nil != err {
return err
}
return InitRPC(serviceTable, logger)
@ -331,8 +332,9 @@ func (r *request) Send(ctx *gin.Context, serviceFlag string, apiFlag string, par
if !r.codeIsSuccess(code, successBusinessCodeList) {
return fmt.Errorf("业务状态码异常 : %v -> %v", code, message)
}
err = parseResponseBody(response.Header.Get("Content-Type"), []byte(data), receiver)
logDataList = append(logDataList, zap.Any("response_body_parse_fail_reason", err.Error()))
if err = parseResponseBody(response.Header.Get("Content-Type"), []byte(data), receiver); nil != err {
logDataList = append(logDataList, zap.Any("response_body_parse_fail_reason", err.Error()))
}
return err
}
@ -364,7 +366,13 @@ func (r *request) GetHttpClient(header map[string]string, timeout ApiTimeout) *h
func (r *request) getFullURLAndBody(serviceConfig *Service, apiConfig *Api, parameter map[string]interface{}) (string, []byte) {
fullURL := strings.TrimRight(serviceConfig.Domain, "/") + "/" + strings.TrimLeft(apiConfig.URI, "/")
for name, val := range parameter {
fullURL = strings.ReplaceAll(fullURL, "{{"+name+"}}", fmt.Sprintf("%v", val))
paramTpl := "{{" + name + "}}"
if !strings.Contains(fullURL, paramTpl) {
continue
}
fullURL = strings.ReplaceAll(fullURL, paramTpl, fmt.Sprintf("%v", val))
// 替换到URL的参数, 从body删除
delete(parameter, name)
}
parameterPair := make([]string, 0)
var body []byte