Skip to content

Commit

Permalink
Replace other HTTP method literals
Browse files Browse the repository at this point in the history
  • Loading branch information
yohfee committed Nov 13, 2023
1 parent 53b1fa2 commit fa3e844
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions mackerel.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,27 @@ func (c *Client) Request(req *http.Request) (resp *http.Response, err error) {
}

func requestGet[T any](client *Client, path string) (*T, error) {
return requestNoBody[T](client, "GET", path, nil)
return requestNoBody[T](client, http.MethodGet, path, nil)
}

func requestGetWithParams[T any](client *Client, path string, params url.Values) (*T, error) {
return requestNoBody[T](client, "GET", path, params)
return requestNoBody[T](client, http.MethodGet, path, params)
}

func requestGetAndReturnHeader[T any](client *Client, path string) (*T, http.Header, error) {
return requestInternal[T](client, "GET", path, nil, nil)
return requestInternal[T](client, http.MethodGet, path, nil, nil)
}

func requestPost[T any](client *Client, path string, payload any) (*T, error) {
return requestJSON[T](client, "POST", path, payload)
return requestJSON[T](client, http.MethodPost, path, payload)
}

func requestPut[T any](client *Client, path string, payload any) (*T, error) {
return requestJSON[T](client, "PUT", path, payload)
return requestJSON[T](client, http.MethodPut, path, payload)
}

func requestDelete[T any](client *Client, path string) (*T, error) {
return requestNoBody[T](client, "DELETE", path, nil)
return requestNoBody[T](client, http.MethodDelete, path, nil)
}

func requestJSON[T any](client *Client, method, path string, payload any) (*T, error) {
Expand Down
16 changes: 8 additions & 8 deletions mackerel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ func Test_requestInternal(t *testing.T) {
body io.Reader
hasContentTypeHeader bool
}{
{"GET", nil, false},
{"POST", nil, true},
{"PUT", nil, true},
{"DELETE", nil, true},
{"GET", strings.NewReader("some"), true},
{"POST", strings.NewReader("some"), true},
{"PUT", strings.NewReader("some"), true},
{"DELETE", strings.NewReader("some"), true},
{http.MethodGet, nil, false},
{http.MethodPost, nil, true},
{http.MethodPut, nil, true},
{http.MethodDelete, nil, true},
{http.MethodGet, strings.NewReader("some"), true},
{http.MethodPost, strings.NewReader("some"), true},
{http.MethodPut, strings.NewReader("some"), true},
{http.MethodDelete, strings.NewReader("some"), true},
}
for _, test := range tests {
t.Run(fmt.Sprintf("%s with %v body", test.method, test.body), func(tt *testing.T) {
Expand Down

0 comments on commit fa3e844

Please sign in to comment.