From f80576d8a8d000f5f481cf5b9d494713bfa11dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 2 Jul 2022 13:42:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95BUG=20+=20=E4=BC=98=E5=8C=96=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/rpc.go b/rpc.go index 7bb5fc4..01d54de 100644 --- a/rpc.go +++ b/rpc.go @@ -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