forked from influxdata/influxdb-comparisons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
41 lines (33 loc) · 1.04 KB
/
common.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
package http
import "time"
const DefaultIdleConnectionTimeout = 90 * time.Second
var UseFastHttp = true
var idleConnectionTimeout = DefaultIdleConnectionTimeout
// HTTPClient is a reusable HTTP Client.
type HTTPClientCommon struct {
Host []byte
HostString string
debug int
}
// HTTPClientDoOptions wraps options uses when calling `Do`.
type HTTPClientDoOptions struct {
ContentType string
Authorization string
Debug int
PrettyPrintResponses bool
Path []byte
AuthToken string
Accept string
}
// HTTPClient interface.
type HTTPClient interface {
HostString() string
Do(q *Query, opts *HTTPClientDoOptions) (lag float64, err error)
}
func NewHTTPClient(host string, debug int, dialTimeout time.Duration, readTimeout time.Duration, writeTimeout time.Duration) HTTPClient {
if UseFastHttp {
return NewFastHTTPClient(host, debug, dialTimeout, readTimeout, writeTimeout)
} else {
return NewDefaultHTTPClient(host, debug, dialTimeout, readTimeout, writeTimeout)
}
}