修复full url 构建的BUG
This commit is contained in:
parent
64d697d972
commit
d521e69229
@ -72,8 +72,8 @@ type ApiRequestConfig struct {
|
|||||||
//
|
//
|
||||||
// Date : 15:02 2022/5/2
|
// Date : 15:02 2022/5/2
|
||||||
type Timeout struct {
|
type Timeout struct {
|
||||||
Connect int64 `json:"connect"` // 连接超时
|
Connect int `json:"connect"` // 连接超时
|
||||||
Read int64 `json:"read"` // 读取超时时间
|
Read int `json:"read"` // 读取超时时间
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApiResponse 接口响应结果
|
// ApiResponse 接口响应结果
|
||||||
|
@ -163,8 +163,8 @@ func getHttpClient(apiConfig *ApiRequestConfig, header map[string]string) *httpc
|
|||||||
}
|
}
|
||||||
fullHeader["content-type"] = apiConfig.ContentType
|
fullHeader["content-type"] = apiConfig.ContentType
|
||||||
return httpclient.NewHttpClient().WithHeaders(fullHeader).
|
return httpclient.NewHttpClient().WithHeaders(fullHeader).
|
||||||
WithOption(httpclient.OPT_CONNECTTIMEOUT_MS, time.Duration(apiConfig.Timeout.Connect)*time.Millisecond).
|
WithOption(httpclient.OPT_CONNECTTIMEOUT_MS, apiConfig.Timeout.Connect).
|
||||||
WithOption(httpclient.OPT_TIMEOUT_MS, time.Duration(apiConfig.Timeout.Read)*time.Millisecond)
|
WithOption(httpclient.OPT_TIMEOUT_MS, apiConfig.Timeout.Read)
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildRequestURLAndParam 构建完整请求URL与请求参数
|
// buildRequestURLAndParam 构建完整请求URL与请求参数
|
||||||
@ -202,7 +202,13 @@ func buildRequestURLAndParam(apiConfig *ApiRequestConfig, header map[string]stri
|
|||||||
apiConfig.URI = apiConfig.URI + "?" + strings.Join(paramPair, "&")
|
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 发送请求
|
// send 发送请求
|
||||||
|
Loading…
Reference in New Issue
Block a user