Skip to content

Commit

Permalink
Merge pull request #755 from gzliudan/http_method
Browse files Browse the repository at this point in the history
all: use http package to replace http method names
  • Loading branch information
gzliudan authored Dec 8, 2024
2 parents 05a0f20 + d55dca0 commit fee2577
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ func sendSuccess(conn *wsConn, msg string) error {
func authGitHub(url string) (string, string, common.Address, error) {
// Retrieve the gist from the GitHub Gist APIs
parts := strings.Split(url, "/")
req, _ := http.NewRequest("GET", "https://api.github.com/gists/"+parts[len(parts)-1], nil)
req, _ := http.NewRequest(http.MethodGet, "https://api.github.com/gists/"+parts[len(parts)-1], nil)
if *githubUser != "" {
req.SetBasicAuth(*githubUser, *githubToken)
}
Expand Down
2 changes: 1 addition & 1 deletion node/rpcstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestNewWebsocketUpgradeHandler_websocket(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")
Expand Down
8 changes: 4 additions & 4 deletions p2p/simulations/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,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
}
Expand Down Expand Up @@ -213,18 +213,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
Expand Down
2 changes: 1 addition & 1 deletion rpc/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,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
}
Expand Down

0 comments on commit fee2577

Please sign in to comment.