Skip to content

Commit

Permalink
implement Post for the custom http client
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Aug 21, 2022
1 parent 510acf5 commit 1459730
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
type IHttpClient interface {
Do(req *http.Request) (*http.Response, error)
Get(url string) (*http.Response, error)
Post(url, contentType string, body io.Reader) (resp *http.Response, err error)
}

// Client special http client that can throttle requests per seconds (RPS).
Expand Down Expand Up @@ -80,6 +81,15 @@ func (c *Client) incrRPS() {
}
}

func (c *Client) Post(url, contentType string, body io.Reader) (resp *http.Response, err error) {
req, err := http.NewRequest(http.MethodPost, url, body)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", contentType)
return c.do(req)
}

func (c *Client) Get(url string) (*http.Response, error) {
return c.get(url)
}
Expand Down

0 comments on commit 1459730

Please sign in to comment.