nezha/pkg/utils/http.go

50 lines
906 B
Go
Raw Permalink Normal View History

package utils
import (
"crypto/tls"
"net/http"
"time"
)
var (
HttpClientSkipTlsVerify *http.Client
HttpClient *http.Client
)
func init() {
HttpClientSkipTlsVerify = httpClient(_httpClient{
Transport: httpTransport(_httpTransport{
2024-11-01 02:07:05 -04:00
SkipVerifyTLS: true,
}),
})
HttpClient = httpClient(_httpClient{
Transport: httpTransport(_httpTransport{
2024-11-01 02:07:05 -04:00
SkipVerifyTLS: false,
}),
})
http.DefaultClient.Timeout = time.Minute * 10
}
type _httpTransport struct {
2024-11-01 02:07:05 -04:00
SkipVerifyTLS bool
}
func httpTransport(conf _httpTransport) *http.Transport {
return &http.Transport{
2024-11-01 02:07:05 -04:00
TLSClientConfig: &tls.Config{InsecureSkipVerify: conf.SkipVerifyTLS},
Proxy: http.ProxyFromEnvironment,
}
}
type _httpClient struct {
Transport *http.Transport
}
func httpClient(conf _httpClient) *http.Client {
return &http.Client{
Transport: conf.Transport,
Timeout: time.Minute * 10,
}
}