mirror of
https://github.com/chaitin/SafeLine.git
synced 2026-02-02 06:43:22 +08:00
36 lines
562 B
Go
36 lines
562 B
Go
package utils
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
const proxyName = "HTTPS_PROXY"
|
|
|
|
var httpClient *http.Client
|
|
|
|
func GetHTTPClient() *http.Client {
|
|
if httpClient == nil {
|
|
tr := &http.Transport{
|
|
MaxIdleConns: 10,
|
|
IdleConnTimeout: 30 * time.Second,
|
|
TLSClientConfig: &tls.Config{
|
|
InsecureSkipVerify: true,
|
|
},
|
|
}
|
|
|
|
proxyUrl, existed := os.LookupEnv(proxyName)
|
|
if existed {
|
|
uri, _ := url.Parse(proxyUrl)
|
|
tr.Proxy = http.ProxyURL(uri)
|
|
}
|
|
|
|
httpClient = &http.Client{Transport: tr}
|
|
}
|
|
|
|
return httpClient
|
|
}
|