func SetHttpProxy() (httpclient http.Client) {
ProxyURL, _ := url.Parse(global.HttpProxyUrl)
httpclient = http.Client{
//设置10s超时时间
Timeout: 10 * time.Second,
//http连接池配置
Transport: &http.Transport{
Proxy: http.ProxyURL(ProxyURL),
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100, //默认连接池有100个连接
IdleConnTimeout: 90 * time.Second, //每个连接默认的空闲时间90s(90s内有请求过来,可以复用该连接)
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
},
}
return httpclient
}