From d521e6922950c21d0fdf56c7dae7bbc15c1e20d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 10 Mar 2023 16:29:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dfull=20url=20=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- curl/define.go | 4 ++-- curl/request.go | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/curl/define.go b/curl/define.go index c66c265..e87b130 100644 --- a/curl/define.go +++ b/curl/define.go @@ -72,8 +72,8 @@ type ApiRequestConfig struct { // // Date : 15:02 2022/5/2 type Timeout struct { - Connect int64 `json:"connect"` // 连接超时 - Read int64 `json:"read"` // 读取超时时间 + Connect int `json:"connect"` // 连接超时 + Read int `json:"read"` // 读取超时时间 } // ApiResponse 接口响应结果 diff --git a/curl/request.go b/curl/request.go index f3c6fbc..c3dac62 100644 --- a/curl/request.go +++ b/curl/request.go @@ -163,8 +163,8 @@ func getHttpClient(apiConfig *ApiRequestConfig, header map[string]string) *httpc } fullHeader["content-type"] = apiConfig.ContentType return httpclient.NewHttpClient().WithHeaders(fullHeader). - WithOption(httpclient.OPT_CONNECTTIMEOUT_MS, time.Duration(apiConfig.Timeout.Connect)*time.Millisecond). - WithOption(httpclient.OPT_TIMEOUT_MS, time.Duration(apiConfig.Timeout.Read)*time.Millisecond) + WithOption(httpclient.OPT_CONNECTTIMEOUT_MS, apiConfig.Timeout.Connect). + WithOption(httpclient.OPT_TIMEOUT_MS, apiConfig.Timeout.Read) } // buildRequestURLAndParam 构建完整请求URL与请求参数 @@ -202,7 +202,13 @@ func buildRequestURLAndParam(apiConfig *ApiRequestConfig, header map[string]stri apiConfig.URI = apiConfig.URI + "?" + strings.Join(paramPair, "&") } } - apiConfig.FullURL = strings.ReplaceAll(apiConfig.Domain+"/"+apiConfig.URI, "//", "/") + if strings.HasSuffix(apiConfig.Domain, "/") { + apiConfig.Domain = strings.TrimRight(apiConfig.Domain, "/") + } + if !strings.HasPrefix(apiConfig.URI, "/") { + apiConfig.URI = "/" + apiConfig.URI + } + apiConfig.FullURL = apiConfig.Domain + apiConfig.URI } // send 发送请求