Skip to content

Commit ebab0cc

Browse files
committed
fix variable shadowing error and linter config
1 parent e63ada9 commit ebab0cc

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

.golangci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,28 @@ linters:
1111

1212
run:
1313
deadline: 10m
14+
modules-download-mode: vendor
1415

1516
issues:
17+
exclude-use-default: false
1618
exclude-rules:
1719
- path: _test\.go
1820
linters:
1921
- dupl
2022
- goconst
2123
- gosec
24+
- linters:
25+
- govet
26+
text: 'shadow: declaration of "err" shadows declaration'
27+
- linters:
28+
- golint
29+
text: 'in another file for this package'
2230

2331
linters-settings:
2432
gocyclo:
2533
min-complexity: 10
34+
golint:
35+
min-confidence: 0
36+
govet:
37+
check-shadowing: true
38+

request.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ import (
1313
"github.com/pkg/errors"
1414
)
1515

16-
// client is the global client instance.
17-
var client *http.Client
16+
// cachedClient is the global client instance.
17+
var cachedClient *http.Client
1818

1919
// defaultTimeout is the timeout applied if there is none provided.
2020
var defaultTimeout = 30 * time.Second
2121

2222
// getCachedClient returns the client instance or creates it if it did not exist.
2323
// The client does not follow redirects and has a timeout of defaultTimeout.
2424
func getCachedClient() *http.Client {
25-
if client == nil {
26-
client = GetClient()
25+
if cachedClient == nil {
26+
cachedClient = GetClient()
2727
}
2828

29-
return client
29+
return cachedClient
3030
}
3131

3232
// 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) {
5858
return err
5959
}
6060

61-
client := getClient(params.Timeout)
61+
client := selectClient(params.Timeout)
6262
res, err := client.Do(req)
6363
if err != nil {
6464
return errors.Wrap(err, "failed to send request")
@@ -90,7 +90,7 @@ func DoWithStringResponse(params Params) (result string, returnErr error) {
9090
return "", err
9191
}
9292

93-
client := getClient(params.Timeout)
93+
client := selectClient(params.Timeout)
9494
res, err := client.Do(req)
9595
if err != nil {
9696
return "", errors.Wrap(err, "failed to send request")
@@ -171,9 +171,9 @@ func convertToReader(body interface{}) (io.Reader, error) {
171171
return buffer, nil
172172
}
173173

174-
func getClient(timeout time.Duration) *http.Client {
174+
func selectClient(timeout time.Duration) *http.Client {
175175
if timeout != 0 {
176-
client = GetClient()
176+
client := GetClient()
177177
client.Timeout = timeout
178178
return client
179179
}

request_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ func TestGetClient(t *testing.T) {
4141
stdClient := http.Client{}
4242
r, err := stdClient.Get(ts.URL)
4343
assert.Error(t, err)
44-
r.Body.Close()
44+
assert.NoError(t, r.Body.Close())
4545

4646
client := GetClient()
4747
res, err := client.Get(ts.URL)
4848
assert.Equal(t, "/////", res.Header.Get("Location"))
49-
res.Body.Close()
49+
assert.NoError(t, res.Body.Close())
5050
assert.NoError(t, err)
5151
})
5252
}

0 commit comments

Comments
 (0)