Skip to content

Commit 0bc3bfb

Browse files
committed
refactor: use net/http method strings instead of new method type
1 parent 2b09660 commit 0bc3bfb

4 files changed

Lines changed: 12 additions & 18 deletions

File tree

endpoint.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package payrex
22

3+
import "net/http"
4+
35
// Contains helper methods for common endpoint patterns.
46

57
func (s *service[T]) create(options any) (*T, error) {
@@ -15,7 +17,7 @@ func (s *service[T]) create(options any) (*T, error) {
1517

1618
func (s *service[T]) retrieve(id string) (*T, error) {
1719
return request[T](s.client,
18-
methodGET,
20+
http.MethodGet,
1921
s.path.make(id),
2022
nil,
2123
)
@@ -34,23 +36,23 @@ func (s *service[T]) update(id string, options any) (*T, error) {
3436

3537
func (s *service[T]) delete(id string) (*DeletedResource, error) {
3638
return request[DeletedResource](s.client,
37-
methodDELETE,
39+
http.MethodDelete,
3840
s.path.make(id),
3941
nil,
4042
)
4143
}
4244

4345
func (s *service[T]) list(options any) (*Listing[T], error) {
4446
return request[Listing[T]](s.client,
45-
methodGET,
47+
http.MethodGet,
4648
s.path.make(),
4749
options,
4850
)
4951
}
5052

5153
func (s *service[T]) post(path urlPath, options any) (*T, error) {
5254
return request[T](s.client,
53-
methodPOST,
55+
http.MethodPost,
5456
path,
5557
options,
5658
)
@@ -62,7 +64,7 @@ func (s *service[T]) postID(id string, path urlPath, options any) (*T, error) {
6264

6365
func (s *service[T]) put(path urlPath, options any) (*T, error) {
6466
return request[T](s.client,
65-
methodPUT,
67+
http.MethodPut,
6668
path,
6769
options,
6870
)

method.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

payout.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package payrex
22

3+
import "net/http"
4+
35
// Payout resources are created when you are scheduled to receive money from PayRex.
46
//
57
// Payouts are made depending on the payout schedule for your PayRex merchant account.
@@ -73,7 +75,7 @@ func (s *ServicePayouts) setup() {
7375
// API reference: https://docs.payrexhq.com/docs/api/payout_transactions/list
7476
func (s *ServicePayouts) ListTransactions(id string, options *ListPayoutTransactionsOptions) (*Listing[PayoutTransaction], error) {
7577
return request[Listing[PayoutTransaction]](s.client,
76-
methodGET,
78+
http.MethodGet,
7779
s.path.make(id, "transactions"),
7880
options,
7981
)

request.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
// request makes a request to the PayRex API with the given payload,
1414
// and returns the JSON response parsed into a value.
15-
func request[T any](client *Client, method method, path urlPath, payload any) (*T, error) {
15+
func request[T any](client *Client, method string, path urlPath, payload any) (*T, error) {
1616
reqURL := client.APIBaseURL + string(path)
1717

1818
var req *http.Request
@@ -24,7 +24,7 @@ func request[T any](client *Client, method method, path urlPath, payload any) (*
2424

2525
switch method {
2626
// Put payload in request body
27-
case methodPOST, methodPUT:
27+
case http.MethodPost, http.MethodPut:
2828
req, err = http.NewRequest(string(method), reqURL,
2929
bytes.NewBuffer([]byte(encodedPayload)))
3030
// Put payload in query parameters

0 commit comments

Comments
 (0)