Skip to content

Commit 052c7d8

Browse files
authored
Add linters that check for bugs (#310)
1 parent d4b83da commit 052c7d8

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@ linters:
3434
- asasalint
3535
- asciicheck
3636
- bidichk
37+
- contextcheck
3738
- dupword
39+
- durationcheck
3840
- errcheck
41+
- errchkjson
3942
- errname
4043
- errorlint
4144
- exportloopref
4245
- fatcontext
4346
- forcetypeassert
4447
- gocheckcompilerdirectives
48+
- gochecksumtype
49+
- gocritic
4550
- godot
4651
- gofmt
4752
- gofumpt
@@ -54,6 +59,7 @@ linters:
5459
- intrange
5560
- makezero
5661
- misspell
62+
- musttag
5763
- nilerr
5864
- noctx
5965
- nolintlint

client/nginx.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ type StreamUpstreamServer struct {
8383
}
8484

8585
type apiErrorResponse struct {
86-
RequestID string `json:"request_id"`
87-
Href string
88-
Error apiError
86+
RequestID string `json:"request_id"`
87+
Href string `json:"href"`
88+
Error apiError `json:"error"`
8989
}
9090

9191
func (resp *apiErrorResponse) toString() string {
@@ -94,9 +94,9 @@ func (resp *apiErrorResponse) toString() string {
9494
}
9595

9696
type apiError struct {
97-
Text string
98-
Code string
99-
Status int
97+
Text string `json:"text"`
98+
Code string `json:"code"`
99+
Status int `json:"status"`
100100
}
101101

102102
type internalError struct {

client/nginx_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -602,19 +602,20 @@ func TestClientWithHTTPClient(t *testing.T) {
602602
func TestGetStats_NoStreamEndpoint(t *testing.T) {
603603
t.Parallel()
604604
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
605-
if r.RequestURI == "/" {
605+
switch {
606+
case r.RequestURI == "/":
606607
_, err := w.Write([]byte(`[4, 5, 6, 7, 8, 9]`))
607608
if err != nil {
608609
t.Fatalf("unexpected error: %v", err)
609610
}
610-
} else if r.RequestURI == "/7/" {
611+
case r.RequestURI == "/7/":
611612
_, err := w.Write([]byte(`["nginx","processes","connections","slabs","http","resolvers","ssl"]`))
612613
if err != nil {
613614
t.Fatalf("unexpected error: %v", err)
614615
}
615-
} else if strings.HasPrefix(r.RequestURI, "/7/stream") {
616+
case strings.HasPrefix(r.RequestURI, "/7/stream"):
616617
t.Fatal("Stream endpoint should not be called since it does not exist.")
617-
} else {
618+
default:
618619
_, err := w.Write([]byte(`{}`))
619620
if err != nil {
620621
t.Fatalf("unexpected error: %v", err)
@@ -654,17 +655,18 @@ func TestGetStats_NoStreamEndpoint(t *testing.T) {
654655
func TestGetStats_SSL(t *testing.T) {
655656
t.Parallel()
656657
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
657-
if r.RequestURI == "/" {
658+
switch {
659+
case r.RequestURI == "/":
658660
_, err := w.Write([]byte(`[4, 5, 6, 7, 8, 9]`))
659661
if err != nil {
660662
t.Fatalf("unexpected error: %v", err)
661663
}
662-
} else if r.RequestURI == "/8/" {
664+
case r.RequestURI == "/8/":
663665
_, err := w.Write([]byte(`["nginx","processes","connections","slabs","http","resolvers","ssl","workers"]`))
664666
if err != nil {
665667
t.Fatalf("unexpected error: %v", err)
666668
}
667-
} else if strings.HasPrefix(r.RequestURI, "/8/ssl") {
669+
case strings.HasPrefix(r.RequestURI, "/8/ssl"):
668670
_, err := w.Write([]byte(`{
669671
"handshakes" : 79572,
670672
"handshakes_failed" : 21025,
@@ -684,7 +686,7 @@ func TestGetStats_SSL(t *testing.T) {
684686
if err != nil {
685687
t.Fatalf("unexpected error: %v", err)
686688
}
687-
} else {
689+
default:
688690
_, err := w.Write([]byte(`{}`))
689691
if err != nil {
690692
t.Fatalf("unexpected error: %v", err)

0 commit comments

Comments
 (0)