Skip to content

Commit 5188f7c

Browse files
authored
Merge pull request #5438 from gofogo/chore-linter-usestdlibvars
chore(codebase): enable usestdlibvars for Go constants
2 parents 679ce87 + 8e9f9ba commit 5188f7c

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ linters:
1515
- staticcheck
1616
- unconvert
1717
- unused
18+
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. https://golangci-lint.run/usage/linters/#usestdlibvars
1819
- whitespace
1920
- decorder # Check declaration order and count of types, constants, variables and functions. https://golangci-lint.run/usage/linters/#decorder
2021
- tagalign # Check that struct tags are well aligned. https://golangci-lint.run/usage/linters/#tagalign

provider/godaddy/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
243243
return nil, err
244244
}
245245
// In case of several clients behind NAT we still can hit rate limit
246-
for i := 1; i < 3 && resp != nil && resp.StatusCode == 429; i++ {
246+
for i := 1; i < 3 && resp != nil && resp.StatusCode == http.StatusTooManyRequests; i++ {
247247
retryAfter, err := strconv.ParseInt(resp.Header.Get("Retry-After"), 10, 0)
248248
if err != nil {
249249
log.Error("Rate-limited response did not contain a valid Retry-After header, quota likely exceeded")

provider/ibmcloud/ibmcloud_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
. "github.com/onsi/ginkgo"
3333
"github.com/stretchr/testify/assert"
3434
"github.com/stretchr/testify/mock"
35+
3536
"sigs.k8s.io/external-dns/endpoint"
3637
"sigs.k8s.io/external-dns/plan"
3738
"sigs.k8s.io/external-dns/provider"
@@ -393,7 +394,7 @@ func TestPublicConfig_Validate(t *testing.T) {
393394

394395
// Set mock response
395396
res.Header().Set("Content-type", "application/json")
396-
res.WriteHeader(200)
397+
res.WriteHeader(http.StatusOK)
397398
fmt.Fprintf(res, "%s", `{"success": true, "errors": [["Errors"]], "messages": [["Messages"]], "result": [{"id": "123", "created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "name": "example.com", "original_registrar": "GoDaddy", "original_dnshost": "NameCheap", "status": "active", "paused": false, "original_name_servers": ["ns1.originaldnshost.com"], "name_servers": ["ns001.name.cloud.ibm.com"]}], "result_info": {"page": 1, "per_page": 20, "count": 1, "total_count": 2000}}`)
398399
}))
399400
zoneIDFilterTest := provider.NewZoneIDFilter([]string{"123"})

provider/pihole/clientV6_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestNewPiholeClientV6(t *testing.T) {
114114

115115
// Create a test server
116116
srvr := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) {
117-
if r.URL.Path == "/api/auth" && r.Method == "POST" {
117+
if r.URL.Path == "/api/auth" && r.Method == http.MethodPost {
118118
var requestData map[string]string
119119
json.NewDecoder(r.Body).Decode(&requestData)
120120
defer r.Body.Close()
@@ -178,7 +178,7 @@ func TestNewPiholeClientV6(t *testing.T) {
178178
func TestListRecordsV6(t *testing.T) {
179179
// Create a test server
180180
srvr := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) {
181-
if r.URL.Path == "/api/config/dns/hosts" && r.Method == "GET" {
181+
if r.URL.Path == "/api/config/dns/hosts" && r.Method == http.MethodGet {
182182

183183
w.WriteHeader(http.StatusOK)
184184
w.Header().Set("Content-Type", "application/json")
@@ -201,7 +201,7 @@ func TestListRecordsV6(t *testing.T) {
201201
},
202202
"took": 5
203203
}`))
204-
} else if r.URL.Path == "/api/config/dns/cnameRecords" && r.Method == "GET" {
204+
} else if r.URL.Path == "/api/config/dns/cnameRecords" && r.Method == http.MethodGet {
205205

206206
w.WriteHeader(http.StatusOK)
207207
w.Header().Set("Content-Type", "application/json")
@@ -373,7 +373,7 @@ func TestErrorsV6(t *testing.T) {
373373

374374
// bad record format return by server
375375
srvrErr := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) {
376-
if r.URL.Path == "/api/config/dns/hosts" && r.Method == "GET" {
376+
if r.URL.Path == "/api/config/dns/hosts" && r.Method == http.MethodGet {
377377
w.WriteHeader(http.StatusOK)
378378
w.Header().Set("Content-Type", "application/json")
379379

@@ -388,7 +388,7 @@ func TestErrorsV6(t *testing.T) {
388388
},
389389
"took": 5
390390
}`))
391-
} else if r.URL.Path == "/api/config/dns/cnameRecords" && r.Method == "GET" {
391+
} else if r.URL.Path == "/api/config/dns/cnameRecords" && r.Method == http.MethodGet {
392392
w.WriteHeader(http.StatusOK)
393393
w.Header().Set("Content-Type", "application/json")
394394

@@ -439,7 +439,7 @@ func TestErrorsV6(t *testing.T) {
439439

440440
func TestTokenValidity(t *testing.T) {
441441
srvok := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) {
442-
if r.URL.Path == "/api/auth" && r.Method == "GET" {
442+
if r.URL.Path == "/api/auth" && r.Method == http.MethodGet {
443443
w.WriteHeader(http.StatusOK)
444444
w.Header().Set("Content-Type", "application/json")
445445

@@ -475,7 +475,7 @@ func TestTokenValidity(t *testing.T) {
475475
// Create a test server
476476
srvr := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) {
477477

478-
if r.URL.Path == "/api/auth" && r.Method == "GET" {
478+
if r.URL.Path == "/api/auth" && r.Method == http.MethodGet {
479479
w.WriteHeader(http.StatusOK)
480480
w.Header().Set("Content-Type", "application/json")
481481

@@ -527,7 +527,7 @@ func TestTokenValidity(t *testing.T) {
527527
func TestDo(t *testing.T) {
528528

529529
srvDo := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) {
530-
if r.URL.Path == "/api/auth/ok" && r.Method == "GET" {
530+
if r.URL.Path == "/api/auth/ok" && r.Method == http.MethodGet {
531531
w.Header().Set("Content-Type", "application/json")
532532
w.WriteHeader(http.StatusOK)
533533
// Return bad content
@@ -542,7 +542,7 @@ func TestDo(t *testing.T) {
542542
},
543543
"took": 0.16
544544
}`))
545-
} else if r.URL.Path == "/api/auth" && r.Method == "POST" {
545+
} else if r.URL.Path == "/api/auth" && r.Method == http.MethodPost {
546546
w.Header().Set("Content-Type", "application/json")
547547
w.WriteHeader(http.StatusOK)
548548
// Return bad content
@@ -557,7 +557,7 @@ func TestDo(t *testing.T) {
557557
},
558558
"took": 0.15
559559
}`))
560-
} else if r.URL.Path == "/api/auth" && r.Method == "GET" {
560+
} else if r.URL.Path == "/api/auth" && r.Method == http.MethodGet {
561561
w.WriteHeader(http.StatusUnauthorized)
562562
// Return bad content
563563
w.Write([]byte(`{
@@ -568,7 +568,7 @@ func TestDo(t *testing.T) {
568568
},
569569
"took": 0.14
570570
}`))
571-
} else if r.URL.Path == "/api/auth/418" && r.Method == "GET" {
571+
} else if r.URL.Path == "/api/auth/418" && r.Method == http.MethodGet {
572572
w.WriteHeader(http.StatusTeapot)
573573
// Return bad content
574574
w.Write([]byte(`{
@@ -579,11 +579,11 @@ func TestDo(t *testing.T) {
579579
},
580580
"took": 0.13
581581
}`))
582-
} else if r.URL.Path == "/api/auth/nojson" && r.Method == "GET" {
582+
} else if r.URL.Path == "/api/auth/nojson" && r.Method == http.MethodGet {
583583
// Return bad content
584584
w.WriteHeader(http.StatusTeapot)
585585
w.Write([]byte(`Not a JSON`))
586-
} else if r.URL.Path == "/api/auth/401" && r.Method == "GET" {
586+
} else if r.URL.Path == "/api/auth/401" && r.Method == http.MethodGet {
587587
w.WriteHeader(http.StatusUnauthorized)
588588
// Return bad content
589589
w.Write([]byte(`{
@@ -655,7 +655,7 @@ func TestDo(t *testing.T) {
655655
func TestDoRetryOne(t *testing.T) {
656656
nbCall := 0
657657
srvRetry := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) {
658-
if r.URL.Path == "/api/auth" && r.Method == "GET" {
658+
if r.URL.Path == "/api/auth" && r.Method == http.MethodGet {
659659
w.Header().Set("Content-Type", "application/json")
660660
w.WriteHeader(http.StatusOK)
661661
// Return bad content
@@ -670,7 +670,7 @@ func TestDoRetryOne(t *testing.T) {
670670
},
671671
"took": 0.24
672672
}`))
673-
} else if r.URL.Path == "/api/auth/401" && r.Method == "GET" {
673+
} else if r.URL.Path == "/api/auth/401" && r.Method == http.MethodGet {
674674
if nbCall == 0 {
675675
w.WriteHeader(http.StatusUnauthorized)
676676
// Return bad content
@@ -713,7 +713,7 @@ func TestDoRetryOne(t *testing.T) {
713713
func TestCreateRecordV6(t *testing.T) {
714714
var ep *endpoint.Endpoint
715715
srvr := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) {
716-
if r.Method == "PUT" && (r.URL.Path == "/api/config/dns/hosts/192.168.1.1 test.example.com" ||
716+
if r.Method == http.MethodPut && (r.URL.Path == "/api/config/dns/hosts/192.168.1.1 test.example.com" ||
717717
r.URL.Path == "/api/config/dns/hosts/fc00::1:192:168:1:1 test.example.com" ||
718718
r.URL.Path == "/api/config/dns/cnameRecords/source1.example.com,target1.domain.com" ||
719719
r.URL.Path == "/api/config/dns/cnameRecords/source2.example.com,target2.domain.com,500") {
@@ -846,7 +846,7 @@ func TestCreateRecordV6(t *testing.T) {
846846
func TestDeleteRecordV6(t *testing.T) {
847847
var ep *endpoint.Endpoint
848848
srvr := newTestServerV6(t, func(w http.ResponseWriter, r *http.Request) {
849-
if r.Method == "DELETE" && (r.URL.Path == "/api/config/dns/hosts/192.168.1.1 test.example.com" ||
849+
if r.Method == http.MethodDelete && (r.URL.Path == "/api/config/dns/hosts/192.168.1.1 test.example.com" ||
850850
r.URL.Path == "/api/config/dns/hosts/fc00::1:192:168:1:1 test.example.com" ||
851851
r.URL.Path == "/api/config/dns/cnameRecords/source1.example.com,target1.domain.com" ||
852852
r.URL.Path == "/api/config/dns/cnameRecords/source2.example.com,target2.domain.com,500") {

provider/webhook/webhook_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/stretchr/testify/assert"
3030
"github.com/stretchr/testify/require"
31+
3132
"sigs.k8s.io/external-dns/endpoint"
3233
"sigs.k8s.io/external-dns/plan"
3334
"sigs.k8s.io/external-dns/provider"
@@ -87,7 +88,7 @@ func TestInvalidDomainFilter(t *testing.T) {
8788
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
8889
if r.URL.Path == "/" {
8990
w.Header().Set(webhookapi.ContentTypeHeader, webhookapi.MediaTypeFormatAndVersion)
90-
w.WriteHeader(200)
91+
w.WriteHeader(http.StatusOK)
9192
return
9293
}
9394
w.Write([]byte(`[{

source/skipper_routegroup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (cli *routeGroupClient) getRouteGroupList(url string) (*routeGroupList, err
164164
}
165165
defer resp.Body.Close()
166166

167-
if resp.StatusCode != 200 {
167+
if resp.StatusCode != http.StatusOK {
168168
return nil, fmt.Errorf("failed to get routegroup list from %s, got: %s", url, resp.Status)
169169
}
170170

@@ -178,7 +178,7 @@ func (cli *routeGroupClient) getRouteGroupList(url string) (*routeGroupList, err
178178
}
179179

180180
func (cli *routeGroupClient) get(url string) (*http.Response, error) {
181-
req, err := http.NewRequest("GET", url, nil)
181+
req, err := http.NewRequest(http.MethodGet, url, nil)
182182
if err != nil {
183183
return nil, err
184184
}

0 commit comments

Comments
 (0)