diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index bec1f6d33b..3dfd639144 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -747,7 +747,7 @@ func authTwitter(url string, tokenV1, tokenV2 string) (string, string, string, c func authTwitterWithTokenV1(tweetID string, token string) (string, string, string, common.Address, error) { // Query the tweet details from Twitter url := fmt.Sprintf("https://api.twitter.com/1.1/statuses/show.json?id=%s", tweetID) - req, err := http.NewRequest("GET", url, nil) + req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return "", "", "", common.Address{}, err } @@ -784,7 +784,7 @@ func authTwitterWithTokenV1(tweetID string, token string) (string, string, strin func authTwitterWithTokenV2(tweetID string, token string) (string, string, string, common.Address, error) { // Query the tweet details from Twitter url := fmt.Sprintf("https://api.twitter.com/2/tweets/%s?expansions=author_id&user.fields=profile_image_url", tweetID) - req, err := http.NewRequest("GET", url, nil) + req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return "", "", "", common.Address{}, err } diff --git a/consensus/ethash/sealer.go b/consensus/ethash/sealer.go index ec46963900..340ad440f3 100644 --- a/consensus/ethash/sealer.go +++ b/consensus/ethash/sealer.go @@ -379,7 +379,7 @@ func (s *remoteSealer) notifyWork() { func (s *remoteSealer) sendNotification(ctx context.Context, url string, json []byte, work [4]string) { defer s.reqWG.Done() - req, err := http.NewRequest("POST", url, bytes.NewReader(json)) + req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(json)) if err != nil { s.ethash.config.Log.Warn("Can't create remote miner notification", "err", err) return diff --git a/graphql/graphiql.go b/graphql/graphiql.go index 864ebf57df..576a0cbe95 100644 --- a/graphql/graphiql.go +++ b/graphql/graphiql.go @@ -48,7 +48,7 @@ func errorJSON(msg string) []byte { } func (h GraphiQL) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { + if r.Method != http.MethodGet { respond(w, errorJSON("only GET requests are supported"), http.StatusMethodNotAllowed) return } diff --git a/metrics/librato/client.go b/metrics/librato/client.go index eebe20521b..729c2da9a9 100644 --- a/metrics/librato/client.go +++ b/metrics/librato/client.go @@ -80,7 +80,7 @@ func (c *LibratoClient) PostMetrics(batch Batch) (err error) { return } - if req, err = http.NewRequest("POST", MetricsPostUrl, bytes.NewBuffer(js)); err != nil { + if req, err = http.NewRequest(http.MethodPost, MetricsPostUrl, bytes.NewBuffer(js)); err != nil { return } diff --git a/node/rpcstack_test.go b/node/rpcstack_test.go index 795bc93c83..4d10e61e2d 100644 --- a/node/rpcstack_test.go +++ b/node/rpcstack_test.go @@ -167,7 +167,7 @@ func TestWebsocketOrigins(t *testing.T) { // TestIsWebsocket tests if an incoming websocket upgrade request is handled properly. func TestIsWebsocket(t *testing.T) { - r, _ := http.NewRequest("GET", "/", nil) + r, _ := http.NewRequest(http.MethodGet, "/", nil) assert.False(t, isWebsocket(r)) r.Header.Set("upgrade", "websocket") @@ -294,7 +294,7 @@ func baseRpcRequest(t *testing.T, url, bodyStr string, extraHeaders ...string) * // Create the request. body := bytes.NewReader([]byte(bodyStr)) - req, err := http.NewRequest("POST", url, body) + req, err := http.NewRequest(http.MethodPost, url, body) if err != nil { t.Fatal("could not create http request:", err) } diff --git a/p2p/simulations/http.go b/p2p/simulations/http.go index f3ea879308..7a4f70e9b0 100644 --- a/p2p/simulations/http.go +++ b/p2p/simulations/http.go @@ -102,7 +102,7 @@ type SubscribeOpts struct { // nodes and connections and filtering message events func (c *Client) SubscribeNetwork(events chan *Event, opts SubscribeOpts) (event.Subscription, error) { url := fmt.Sprintf("%s/events?current=%t&filter=%s", c.URL, opts.Current, opts.Filter) - req, err := http.NewRequest("GET", url, nil) + req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return nil, err } @@ -215,18 +215,18 @@ func (c *Client) RPCClient(ctx context.Context, nodeID string) (*rpc.Client, err // Get performs a HTTP GET request decoding the resulting JSON response // into "out" func (c *Client) Get(path string, out interface{}) error { - return c.Send("GET", path, nil, out) + return c.Send(http.MethodGet, path, nil, out) } // Post performs a HTTP POST request sending "in" as the JSON body and // decoding the resulting JSON response into "out" func (c *Client) Post(path string, in, out interface{}) error { - return c.Send("POST", path, in, out) + return c.Send(http.MethodPost, path, in, out) } // Delete performs a HTTP DELETE request func (c *Client) Delete(path string) error { - return c.Send("DELETE", path, nil, nil) + return c.Send(http.MethodDelete, path, nil, nil) } // Send performs a HTTP request, sending "in" as the JSON request body and diff --git a/rpc/http.go b/rpc/http.go index 074c57ab1a..8712f99610 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -209,7 +209,7 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos if err != nil { return nil, err } - req, err := http.NewRequestWithContext(ctx, "POST", hc.url, io.NopCloser(bytes.NewReader(body))) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, hc.url, io.NopCloser(bytes.NewReader(body))) if err != nil { return nil, err }