From e02ee1fef92010e97f1caf7537bb57cfad98d800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 7 May 2025 21:59:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dpath=20param=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httpclient/resty.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/httpclient/resty.go b/httpclient/resty.go index e091457..6c3e76d 100644 --- a/httpclient/resty.go +++ b/httpclient/resty.go @@ -59,12 +59,8 @@ func NewRestyClient(reqConfig *define.Request) (*resty.Client, *resty.Request) { } request.SetHeaders(header) // 设置header request.URL = reqConfig.FullUrl // 请求接口 - for pathParamName, pathParamValue := range reqConfig.PathParam { - if len(pathParamValue) == 0 { - continue - } - reqConfig.FullUrl = strings.ReplaceAll(reqConfig.FullUrl, "{"+pathParamName+"}", pathParamValue) - } + // 设置url参数, url path格式需要是 /user/{user_id}/detail格式, {user_id} 会自动替换 + request.SetPathParams(reqConfig.PathParam) request.Method = reqConfig.Method // 请求方法 cookieList := make([]*http.Cookie, 0) for cookieName, cookieValue := range reqConfig.Cookie { @@ -81,7 +77,7 @@ func NewRestyClient(reqConfig *define.Request) (*resty.Client, *resty.Request) { return client, request } -// setRestyBody 设置请求BODY +// setRestyBody 设置请求BODY TODO: 支持xml / yml等 // // Author : go_developer@163.com<白茶清欢> //