-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
42 lines (37 loc) · 877 Bytes
/
util.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
package bond
import (
"crypto/tls"
"net"
"net/http"
"sync"
"time"
)
const httpClientTimeout = 10 * time.Minute
var httpClientPool *sync.Pool
func init() {
httpClientPool = &sync.Pool{
New: func() interface{} {
return &http.Client{
Timeout: httpClientTimeout,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{},
Proxy: http.ProxyFromEnvironment,
DisableCompression: false,
DisableKeepAlives: true,
IdleConnTimeout: 20 * time.Second,
MaxIdleConnsPerHost: 10,
MaxIdleConns: 50,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 0,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
},
}
},
}
}
func GetHTTPClient() *http.Client { return httpClientPool.Get().(*http.Client) }
func PutHTTPClient(c *http.Client) {
httpClientPool.Put(c)
}