Skip to content

Commit 163e996

Browse files
authored
all: use http package to replace http method names (#26535)
1 parent e4fa2cf commit 163e996

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

cmd/faucet/faucet.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ func authTwitter(url string, tokenV1, tokenV2 string) (string, string, string, c
747747
func authTwitterWithTokenV1(tweetID string, token string) (string, string, string, common.Address, error) {
748748
// Query the tweet details from Twitter
749749
url := fmt.Sprintf("https://api.twitter.com/1.1/statuses/show.json?id=%s", tweetID)
750-
req, err := http.NewRequest("GET", url, nil)
750+
req, err := http.NewRequest(http.MethodGet, url, nil)
751751
if err != nil {
752752
return "", "", "", common.Address{}, err
753753
}
@@ -784,7 +784,7 @@ func authTwitterWithTokenV1(tweetID string, token string) (string, string, strin
784784
func authTwitterWithTokenV2(tweetID string, token string) (string, string, string, common.Address, error) {
785785
// Query the tweet details from Twitter
786786
url := fmt.Sprintf("https://api.twitter.com/2/tweets/%s?expansions=author_id&user.fields=profile_image_url", tweetID)
787-
req, err := http.NewRequest("GET", url, nil)
787+
req, err := http.NewRequest(http.MethodGet, url, nil)
788788
if err != nil {
789789
return "", "", "", common.Address{}, err
790790
}

consensus/ethash/sealer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func (s *remoteSealer) notifyWork() {
379379
func (s *remoteSealer) sendNotification(ctx context.Context, url string, json []byte, work [4]string) {
380380
defer s.reqWG.Done()
381381

382-
req, err := http.NewRequest("POST", url, bytes.NewReader(json))
382+
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(json))
383383
if err != nil {
384384
s.ethash.config.Log.Warn("Can't create remote miner notification", "err", err)
385385
return

graphql/graphiql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func errorJSON(msg string) []byte {
4848
}
4949

5050
func (h GraphiQL) ServeHTTP(w http.ResponseWriter, r *http.Request) {
51-
if r.Method != "GET" {
51+
if r.Method != http.MethodGet {
5252
respond(w, errorJSON("only GET requests are supported"), http.StatusMethodNotAllowed)
5353
return
5454
}

metrics/librato/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (c *LibratoClient) PostMetrics(batch Batch) (err error) {
8080
return
8181
}
8282

83-
if req, err = http.NewRequest("POST", MetricsPostUrl, bytes.NewBuffer(js)); err != nil {
83+
if req, err = http.NewRequest(http.MethodPost, MetricsPostUrl, bytes.NewBuffer(js)); err != nil {
8484
return
8585
}
8686

node/rpcstack_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func TestWebsocketOrigins(t *testing.T) {
167167

168168
// TestIsWebsocket tests if an incoming websocket upgrade request is handled properly.
169169
func TestIsWebsocket(t *testing.T) {
170-
r, _ := http.NewRequest("GET", "/", nil)
170+
r, _ := http.NewRequest(http.MethodGet, "/", nil)
171171

172172
assert.False(t, isWebsocket(r))
173173
r.Header.Set("upgrade", "websocket")
@@ -294,7 +294,7 @@ func baseRpcRequest(t *testing.T, url, bodyStr string, extraHeaders ...string) *
294294

295295
// Create the request.
296296
body := bytes.NewReader([]byte(bodyStr))
297-
req, err := http.NewRequest("POST", url, body)
297+
req, err := http.NewRequest(http.MethodPost, url, body)
298298
if err != nil {
299299
t.Fatal("could not create http request:", err)
300300
}

p2p/simulations/http.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ type SubscribeOpts struct {
102102
// nodes and connections and filtering message events
103103
func (c *Client) SubscribeNetwork(events chan *Event, opts SubscribeOpts) (event.Subscription, error) {
104104
url := fmt.Sprintf("%s/events?current=%t&filter=%s", c.URL, opts.Current, opts.Filter)
105-
req, err := http.NewRequest("GET", url, nil)
105+
req, err := http.NewRequest(http.MethodGet, url, nil)
106106
if err != nil {
107107
return nil, err
108108
}
@@ -215,18 +215,18 @@ func (c *Client) RPCClient(ctx context.Context, nodeID string) (*rpc.Client, err
215215
// Get performs a HTTP GET request decoding the resulting JSON response
216216
// into "out"
217217
func (c *Client) Get(path string, out interface{}) error {
218-
return c.Send("GET", path, nil, out)
218+
return c.Send(http.MethodGet, path, nil, out)
219219
}
220220

221221
// Post performs a HTTP POST request sending "in" as the JSON body and
222222
// decoding the resulting JSON response into "out"
223223
func (c *Client) Post(path string, in, out interface{}) error {
224-
return c.Send("POST", path, in, out)
224+
return c.Send(http.MethodPost, path, in, out)
225225
}
226226

227227
// Delete performs a HTTP DELETE request
228228
func (c *Client) Delete(path string) error {
229-
return c.Send("DELETE", path, nil, nil)
229+
return c.Send(http.MethodDelete, path, nil, nil)
230230
}
231231

232232
// Send performs a HTTP request, sending "in" as the JSON request body and

rpc/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos
209209
if err != nil {
210210
return nil, err
211211
}
212-
req, err := http.NewRequestWithContext(ctx, "POST", hc.url, io.NopCloser(bytes.NewReader(body)))
212+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, hc.url, io.NopCloser(bytes.NewReader(body)))
213213
if err != nil {
214214
return nil, err
215215
}

0 commit comments

Comments
 (0)