@@ -13,20 +13,20 @@ import (
13
13
"github.com/pkg/errors"
14
14
)
15
15
16
- // client is the global client instance.
17
- var client * http.Client
16
+ // cachedClient is the global client instance.
17
+ var cachedClient * http.Client
18
18
19
19
// defaultTimeout is the timeout applied if there is none provided.
20
20
var defaultTimeout = 30 * time .Second
21
21
22
22
// getCachedClient returns the client instance or creates it if it did not exist.
23
23
// The client does not follow redirects and has a timeout of defaultTimeout.
24
24
func getCachedClient () * http.Client {
25
- if client == nil {
26
- client = GetClient ()
25
+ if cachedClient == nil {
26
+ cachedClient = GetClient ()
27
27
}
28
28
29
- return client
29
+ return cachedClient
30
30
}
31
31
32
32
// GetClient returns an http client that does not follow redirects and has a timeout of defaultTimeout.
@@ -58,7 +58,7 @@ func Do(params Params, responseBody interface{}) (returnErr error) {
58
58
return err
59
59
}
60
60
61
- client := getClient (params .Timeout )
61
+ client := selectClient (params .Timeout )
62
62
res , err := client .Do (req )
63
63
if err != nil {
64
64
return errors .Wrap (err , "failed to send request" )
@@ -90,7 +90,7 @@ func DoWithStringResponse(params Params) (result string, returnErr error) {
90
90
return "" , err
91
91
}
92
92
93
- client := getClient (params .Timeout )
93
+ client := selectClient (params .Timeout )
94
94
res , err := client .Do (req )
95
95
if err != nil {
96
96
return "" , errors .Wrap (err , "failed to send request" )
@@ -171,9 +171,9 @@ func convertToReader(body interface{}) (io.Reader, error) {
171
171
return buffer , nil
172
172
}
173
173
174
- func getClient (timeout time.Duration ) * http.Client {
174
+ func selectClient (timeout time.Duration ) * http.Client {
175
175
if timeout != 0 {
176
- client = GetClient ()
176
+ client : = GetClient ()
177
177
client .Timeout = timeout
178
178
return client
179
179
}
0 commit comments