Files
SafeLine/management/webserver/utils/httpclient.go
2024-07-04 17:54:34 +08:00

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
}