Skip to content

Commit

Permalink
Add client.OnBeforeRequest(...) (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
LBGarber authored May 10, 2022
1 parent 5589a2c commit a044d85
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ type Client struct {
Volumes *Resource
}

type Request = resty.Request

func init() {
// Wether or not we will enable Resty debugging output
if apiDebug, ok := os.LookupEnv("LINODE_DEBUG"); ok {
Expand Down Expand Up @@ -151,6 +153,13 @@ func (c *Client) SetDebug(debug bool) *Client {
return c
}

// OnBeforeRequest adds a handler to the request body to run before the request is sent
func (c *Client) OnBeforeRequest(m func(request *Request) error) {
c.resty.OnBeforeRequest(func(client *resty.Client, req *resty.Request) error {
return m(req)
})
}

// SetBaseURL sets the base URL of the Linode v4 API (https://api.linode.com/v4)
func (c *Client) SetBaseURL(baseURL string) *Client {
baseURLPath, _ := url.Parse(baseURL)
Expand Down

0 comments on commit a044d85

Please sign in to comment.