diff --git a/app/victoria-metrics/main.go b/app/victoria-metrics/main.go index 0233aff8ce..231fae32e2 100644 --- a/app/victoria-metrics/main.go +++ b/app/victoria-metrics/main.go @@ -92,7 +92,7 @@ func main() { func requestHandler(w http.ResponseWriter, r *http.Request) bool { if r.URL.Path == "/" { - if r.Method != "GET" { + if r.Method != http.MethodGet { return false } w.Header().Add("Content-Type", "text/html; charset=utf-8") diff --git a/app/vmagent/main.go b/app/vmagent/main.go index 9b78b13f39..4cfa4f39d6 100644 --- a/app/vmagent/main.go +++ b/app/vmagent/main.go @@ -208,7 +208,7 @@ func getAuthTokenFromPath(path string) (*auth.Token, error) { func requestHandler(w http.ResponseWriter, r *http.Request) bool { if r.URL.Path == "/" { - if r.Method != "GET" { + if r.Method != http.MethodGet { return false } w.Header().Add("Content-Type", "text/html; charset=utf-8") diff --git a/app/vmagent/prometheusimport/request_handler_test.go b/app/vmagent/prometheusimport/request_handler_test.go index 1252ee8c74..0b5f9d6ac5 100644 --- a/app/vmagent/prometheusimport/request_handler_test.go +++ b/app/vmagent/prometheusimport/request_handler_test.go @@ -23,7 +23,7 @@ var ( func TestInsertHandler(t *testing.T) { setUp() defer tearDown() - req := httptest.NewRequest("POST", "/insert/0/api/v1/import/prometheus", bytes.NewBufferString(`{"foo":"bar"} + req := httptest.NewRequest(http.MethodPost, "/insert/0/api/v1/import/prometheus", bytes.NewBufferString(`{"foo":"bar"} go_memstats_alloc_bytes_total 1`)) if err := InsertHandler(nil, req); err != nil { t.Errorf("unxepected error %s", err) diff --git a/app/vmalert/web.go b/app/vmalert/web.go index 668a758b0c..77a06aa0dd 100644 --- a/app/vmalert/web.go +++ b/app/vmalert/web.go @@ -57,7 +57,7 @@ func (rh *requestHandler) handler(w http.ResponseWriter, r *http.Request) bool { switch r.URL.Path { case "/", "/vmalert", "/vmalert/": - if r.Method != "GET" { + if r.Method != http.MethodGet { httpserver.Errorf(w, r, "path %q supports only GET method", r.URL.Path) return false } diff --git a/app/vmauth/main.go b/app/vmauth/main.go index ec180004d1..f64f567667 100644 --- a/app/vmauth/main.go +++ b/app/vmauth/main.go @@ -169,7 +169,7 @@ func tryProcessingRequest(w http.ResponseWriter, r *http.Request, targetURL *url if err != nil { remoteAddr := httpserver.GetQuotedRemoteAddr(r) requestURI := httpserver.GetRequestURI(r) - if r.Method == "POST" || r.Method == "PUT" { + if r.Method == http.MethodPost || r.Method == http.MethodPut { // It is impossible to retry POST and PUT requests, // since we already proxied the request body to the backend. err = &httpserver.ErrorWithStatusCode{ diff --git a/app/vmctl/vm_native.go b/app/vmctl/vm_native.go index dd85d8b748..b86dc81f76 100644 --- a/app/vmctl/vm_native.go +++ b/app/vmctl/vm_native.go @@ -147,7 +147,7 @@ func (p *vmNativeProcessor) runSingle(ctx context.Context, f filter, srcURL, dst sync := make(chan struct{}) go func() { defer func() { close(sync) }() - req, err := http.NewRequestWithContext(ctx, "POST", dstURL, pr) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, dstURL, pr) if err != nil { log.Fatalf("cannot create import request to %q: %s", p.dst.addr, err) } @@ -198,7 +198,7 @@ func (p *vmNativeProcessor) runSingle(ctx context.Context, f filter, srcURL, dst func (p *vmNativeProcessor) getSourceTenants(ctx context.Context, f filter) ([]string, error) { u := fmt.Sprintf("%s/%s", p.src.addr, nativeTenantsAddr) - req, err := http.NewRequestWithContext(ctx, "GET", u, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil) if err != nil { return nil, fmt.Errorf("cannot create request to %q: %s", u, err) } @@ -232,7 +232,7 @@ func (p *vmNativeProcessor) getSourceTenants(ctx context.Context, f filter) ([]s } func (p *vmNativeProcessor) exportPipe(ctx context.Context, url string, f filter) (io.ReadCloser, error) { - req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { return nil, fmt.Errorf("cannot create request to %q: %s", p.src.addr, err) } diff --git a/lib/httpserver/httpserver.go b/lib/httpserver/httpserver.go index 09a54c5052..dcb68cd9f2 100644 --- a/lib/httpserver/httpserver.go +++ b/lib/httpserver/httpserver.go @@ -674,7 +674,7 @@ func WriteAPIHelp(w io.Writer, pathList [][2]string) { // GetRequestURI returns requestURI for r. func GetRequestURI(r *http.Request) string { requestURI := r.RequestURI - if r.Method != "POST" { + if r.Method != http.MethodPost { return requestURI } _ = r.ParseForm() diff --git a/lib/promscrape/client.go b/lib/promscrape/client.go index bf30e0369b..c74fea462e 100644 --- a/lib/promscrape/client.go +++ b/lib/promscrape/client.go @@ -185,7 +185,7 @@ func newClient(sw *ScrapeWork, ctx context.Context) *client { func (c *client) GetStreamReader() (*streamReader, error) { deadline := time.Now().Add(c.sc.Timeout) ctx, cancel := context.WithDeadline(c.ctx, deadline) - req, err := http.NewRequestWithContext(ctx, "GET", c.scrapeURL, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.scrapeURL, nil) if err != nil { cancel() return nil, fmt.Errorf("cannot create request for %q: %w", c.scrapeURL, err) diff --git a/lib/promscrape/discovery/kuma/api.go b/lib/promscrape/discovery/kuma/api.go index 0e3560f431..32e5411d2e 100644 --- a/lib/promscrape/discovery/kuma/api.go +++ b/lib/promscrape/discovery/kuma/api.go @@ -151,7 +151,7 @@ func (cfg *apiConfig) updateTargetsLabels(ctx context.Context) error { logger.Panicf("BUG: cannot marshal Kuma discovery request: %s", err) } updateRequestFunc := func(req *http.Request) { - req.Method = "POST" + req.Method = http.MethodPost req.Body = io.NopCloser(bytes.NewReader(requestBody)) req.Header.Set("Accept", "application/json") req.Header.Set("Content-Type", "application/json") diff --git a/lib/promscrape/discoveryutils/client.go b/lib/promscrape/discoveryutils/client.go index 50f5ea0dbf..83d7fed2cd 100644 --- a/lib/promscrape/discoveryutils/client.go +++ b/lib/promscrape/discoveryutils/client.go @@ -225,7 +225,7 @@ func (c *Client) getAPIResponseWithParamsAndClientCtx(ctx context.Context, clien deadline := time.Now().Add(client.ReadTimeout) ctx, cancel := context.WithDeadline(ctx, deadline) defer cancel() - req, err := http.NewRequestWithContext(ctx, "GET", u.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil) if err != nil { return nil, fmt.Errorf("cannot create request for %q: %w", requestURL, err) }