-
Notifications
You must be signed in to change notification settings - Fork 16
/
client.go
39 lines (33 loc) · 904 Bytes
/
client.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
package httpclient
import (
"net/http"
"github.com/consensys/quorum-key-manager/pkg/http/transport"
)
// Client is an HTTP client
type Client interface {
// Do sends an HTTP request and returns an HTTP response, following
// policy (such as redirects, cookies, auth)
Do(*http.Request) (*http.Response, error)
// CloseIdleConnections closes any connections on its Transport which
// were previously connected from previous requests but are now
// sitting idle in a "keep-alive" state. It does not interrupt any
// connections currently in use.
CloseIdleConnections()
}
// New creates a new HTTP client
func New(
cfg *Config,
trnsprt http.RoundTripper,
) (Client, error) {
var err error
if trnsprt == nil {
trnsprt, err = transport.New(cfg.Transport)
if err != nil {
return nil, err
}
}
return &http.Client{
Transport: trnsprt,
Timeout: cfg.Timeout.Duration,
}, nil
}