...
1
2
3
4
5
6
7 package resty
8
9 import (
10 "net"
11 "net/http"
12 "runtime"
13 "time"
14 )
15
16 func createTransport(localAddr net.Addr) *http.Transport {
17 dialer := &net.Dialer{
18 Timeout: 30 * time.Second,
19 KeepAlive: 30 * time.Second,
20 DualStack: true,
21 }
22 if localAddr != nil {
23 dialer.LocalAddr = localAddr
24 }
25 return &http.Transport{
26 Proxy: http.ProxyFromEnvironment,
27 DialContext: dialer.DialContext,
28 MaxIdleConns: 100,
29 IdleConnTimeout: 90 * time.Second,
30 TLSHandshakeTimeout: 10 * time.Second,
31 ExpectContinueTimeout: 1 * time.Second,
32 MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1,
33 }
34 }
35
View as plain text