diff --git a/.golangci.yml b/.golangci.yml index fb5d208..f5a7f9d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -31,6 +31,7 @@ linters: - staticcheck - unconvert - unused + - usestdlibvars - wastedassign issues: diff --git a/prometheus/promhttp/http_test.go b/prometheus/promhttp/http_test.go index c3a433c..a763da4 100644 --- a/prometheus/promhttp/http_test.go +++ b/prometheus/promhttp/http_test.go @@ -131,7 +131,7 @@ func TestHandlerErrorHandling(t *testing.T) { logger := log.New(logBuf, "", 0) writer := httptest.NewRecorder() - request, _ := http.NewRequest("GET", "/", nil) + request, _ := http.NewRequest(http.MethodGet, "/", nil) request.Header.Add("Accept", "test/plain") mReg := &mockTransactionGatherer{g: reg} @@ -252,7 +252,7 @@ func TestInstrumentMetricHandler(t *testing.T) { // Do it again to test idempotency. InstrumentMetricHandler(reg, HandlerForTransactional(mReg, HandlerOpts{})) writer := httptest.NewRecorder() - request, _ := http.NewRequest("GET", "/", nil) + request, _ := http.NewRequest(http.MethodGet, "/", nil) request.Header.Add(acceptHeader, acceptTextPlain) handler.ServeHTTP(writer, request) @@ -311,7 +311,7 @@ func TestHandlerMaxRequestsInFlight(t *testing.T) { w1 := httptest.NewRecorder() w2 := httptest.NewRecorder() w3 := httptest.NewRecorder() - request, _ := http.NewRequest("GET", "/", nil) + request, _ := http.NewRequest(http.MethodGet, "/", nil) request.Header.Add(acceptHeader, acceptTextPlain) c := blockingCollector{Block: make(chan struct{}), CollectStarted: make(chan struct{}, 1)} @@ -348,7 +348,7 @@ func TestHandlerTimeout(t *testing.T) { handler := HandlerFor(reg, HandlerOpts{Timeout: time.Millisecond}) w := httptest.NewRecorder() - request, _ := http.NewRequest("GET", "/", nil) + request, _ := http.NewRequest(http.MethodGet, "/", nil) request.Header.Add("Accept", "test/plain") c := blockingCollector{Block: make(chan struct{}), CollectStarted: make(chan struct{}, 1)} @@ -372,7 +372,7 @@ func TestInstrumentMetricHandlerWithCompression(t *testing.T) { handler := InstrumentMetricHandler(reg, HandlerForTransactional(mReg, HandlerOpts{DisableCompression: false})) compression := Zstd writer := httptest.NewRecorder() - request, _ := http.NewRequest("GET", "/", nil) + request, _ := http.NewRequest(http.MethodGet, "/", nil) request.Header.Add(acceptHeader, acceptTextPlain) request.Header.Add(acceptEncodingHeader, string(compression)) @@ -533,7 +533,7 @@ func TestNegotiateEncodingWriter(t *testing.T) { } for _, test := range testCases { - request, _ := http.NewRequest("GET", "/", nil) + request, _ := http.NewRequest(http.MethodGet, "/", nil) request.Header.Add(acceptEncodingHeader, test.acceptEncoding) rr := httptest.NewRecorder() _, encodingHeader, _, err := negotiateEncodingWriter(request, rr, test.offeredCompressions) @@ -631,7 +631,7 @@ func BenchmarkCompression(b *testing.B) { b.Run(benchmark.name+"_"+size.name, func(b *testing.B) { for i := 0; i < b.N; i++ { writer := httptest.NewRecorder() - request, _ := http.NewRequest("GET", "/", nil) + request, _ := http.NewRequest(http.MethodGet, "/", nil) request.Header.Add(acceptEncodingHeader, benchmark.compressionType) handler.ServeHTTP(writer, request) } diff --git a/prometheus/promhttp/instrument_client_test.go b/prometheus/promhttp/instrument_client_test.go index ce7c4da..5613349 100644 --- a/prometheus/promhttp/instrument_client_test.go +++ b/prometheus/promhttp/instrument_client_test.go @@ -223,7 +223,7 @@ func TestClientMiddlewareAPI_WithRequestContext(t *testing.T) { })) defer backend.Close() - req, err := http.NewRequest("GET", backend.URL, nil) + req, err := http.NewRequest(http.MethodGet, backend.URL, nil) if err != nil { t.Fatalf("%v", err) } @@ -276,7 +276,7 @@ func TestClientMiddlewareAPIWithRequestContextTimeout(t *testing.T) { })) defer backend.Close() - req, err := http.NewRequest("GET", backend.URL, nil) + req, err := http.NewRequest(http.MethodGet, backend.URL, nil) if err != nil { t.Fatalf("%v", err) } diff --git a/prometheus/promhttp/instrument_server_test.go b/prometheus/promhttp/instrument_server_test.go index 8aef09f..600f593 100644 --- a/prometheus/promhttp/instrument_server_test.go +++ b/prometheus/promhttp/instrument_server_test.go @@ -418,7 +418,7 @@ func TestMiddlewareAPI(t *testing.T) { _, _ = w.Write([]byte("OK")) }) - r, _ := http.NewRequest("GET", "www.example.com", nil) + r, _ := http.NewRequest(http.MethodGet, "www.example.com", nil) w := httptest.NewRecorder() chain.ServeHTTP(w, r) @@ -432,7 +432,7 @@ func TestMiddlewareAPI_WithExemplars(t *testing.T) { _, _ = w.Write([]byte("OK")) }, WithExemplarFromContext(func(_ context.Context) prometheus.Labels { return exemplar })) - r, _ := http.NewRequest("GET", "www.example.com", nil) + r, _ := http.NewRequest(http.MethodGet, "www.example.com", nil) w := httptest.NewRecorder() chain.ServeHTTP(w, r) diff --git a/prometheus/registry_test.go b/prometheus/registry_test.go index f6bca22..b8505c7 100644 --- a/prometheus/registry_test.go +++ b/prometheus/registry_test.go @@ -714,7 +714,7 @@ collected metric "broken_metric" { label: label: