forked from uber/gonduit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
46 lines (38 loc) · 970 Bytes
/
http.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 core
import (
"crypto/tls"
"net/http"
"time"
)
// An Client performs http.Requests. It captures the Do
// method of the http.Client.
type Client interface {
Do(*http.Request) (*http.Response, error)
}
// ClientOptions are options that can be set on the HTTP client.
type ClientOptions struct {
APIToken string
Cert string
CertUser string
SessionKey string
InsecureSkipVerify bool
Timeout time.Duration
// If set, Client will be used to execute HTTP requests.
// Otherwise, one is created with default settings and
// InsecureSkipVerify respected.
Client Client
}
// makeHttpClient creates a new HTTP client for making API requests.
func makeHTTPClient(options *ClientOptions) Client {
if options.Client != nil {
return options.Client
}
return &http.Client{
Timeout: options.Timeout,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: options.InsecureSkipVerify,
},
},
}
}