File tree 2 files changed +11
-7
lines changed
2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -36,14 +36,18 @@ var DefaultRoundTripper http.RoundTripper = &http.Transport{
36
36
TLSHandshakeTimeout : 10 * time .Second ,
37
37
}
38
38
39
+ type HttpClient interface {
40
+ Do (req * http.Request ) (* http.Response , error )
41
+ }
42
+
39
43
// Config defines configuration parameters for a new client.
40
44
type Config struct {
41
45
// The address of the Prometheus to connect to.
42
46
Address string
43
47
44
48
// Client is used by the Client to drive HTTP requests. If not provided,
45
- // a new one based on the provided RoundTripper (or DefaultRoundTripper) will be used.
46
- Client * http. Client
49
+ // a new http.Client based on the provided RoundTripper (or DefaultRoundTripper) will be used.
50
+ Client HttpClient
47
51
48
52
// RoundTripper is used by the Client to drive HTTP requests. If not
49
53
// provided, DefaultRoundTripper will be used.
@@ -57,13 +61,13 @@ func (cfg *Config) roundTripper() http.RoundTripper {
57
61
return cfg .RoundTripper
58
62
}
59
63
60
- func (cfg * Config ) client () http. Client {
64
+ func (cfg * Config ) client () HttpClient {
61
65
if cfg .Client == nil {
62
- return http.Client {
66
+ return & http.Client {
63
67
Transport : cfg .roundTripper (),
64
68
}
65
69
}
66
- return * cfg .Client
70
+ return cfg .Client
67
71
}
68
72
69
73
func (cfg * Config ) validate () error {
@@ -101,7 +105,7 @@ func NewClient(cfg Config) (Client, error) {
101
105
102
106
type httpClient struct {
103
107
endpoint * url.URL
104
- client http. Client
108
+ client HttpClient
105
109
}
106
110
107
111
func (c * httpClient ) URL (ep string , args map [string ]string ) * url.URL {
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ func TestClientURL(t *testing.T) {
105
105
106
106
hclient := & httpClient {
107
107
endpoint : ep ,
108
- client : http.Client {Transport : DefaultRoundTripper },
108
+ client : & http.Client {Transport : DefaultRoundTripper },
109
109
}
110
110
111
111
u := hclient .URL (test .endpoint , test .args )
You can’t perform that action at this time.
0 commit comments