forked from openziti/sdk-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent.go
47 lines (40 loc) · 1.21 KB
/
component.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
47
package edge_apis
import (
"crypto/x509"
"github.com/openziti/edge-api/rest_util"
"net/http"
"net/http/cookiejar"
"time"
)
// Components provides the basic shared lower level pieces used to assemble go-swagger/openapi clients. These
// components are interconnected and have references to each other. This struct is used to set, move, and manage
// them as a set.
type Components struct {
HttpClient *http.Client
HttpTransport *http.Transport
CaPool *x509.CertPool
}
// NewComponents assembles a new set of components with reasonable production defaults.
func NewComponents() *Components {
tlsClientConfig, _ := rest_util.NewTlsConfig()
httpTransport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: tlsClientConfig,
ForceAttemptHTTP2: true,
MaxIdleConns: 10,
IdleConnTimeout: 10 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
jar, _ := cookiejar.New(nil)
httpClient := &http.Client{
Transport: httpTransport,
CheckRedirect: nil,
Jar: jar,
Timeout: 10 * time.Second,
}
return &Components{
HttpClient: httpClient,
HttpTransport: httpTransport,
}
}