/
helpers.go
46 lines (42 loc) · 1015 Bytes
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package storages
import (
"crypto/tls"
"net"
"net/http"
"net/url"
"time"
)
const subscriberFilename = "subscribers.json"
const persistentFilename = "persistents.json"
func makeHttpClient(u *url.URL) *http.Client {
transport := makeHttpTransport(u)
client := &http.Client{
Transport: transport,
Timeout: 0,
}
return client
}
func makeHttpTransport(u *url.URL) *http.Transport {
skipInsecure := false
if u.Query().Get("insecure-skip-verify") != "" {
skipInsecure = true
val := u.Query()
val.Del("insecure-skip-verify")
u.RawQuery = val.Encode()
}
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: skipInsecure,
},
}
}