Skip to content

Commit

Permalink
impl PostForm for custom client
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Aug 21, 2022
1 parent 1459730 commit b7f0076
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
"sync"
"sync/atomic"
"time"
Expand All @@ -15,6 +17,7 @@ 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)
PostForm(url string, data url.Values) (resp *http.Response, err error)
}

// Client special http client that can throttle requests per seconds (RPS).
Expand Down Expand Up @@ -90,6 +93,10 @@ func (c *Client) Post(url, contentType string, body io.Reader) (resp *http.Respo
return c.do(req)
}

func (c *Client) PostForm(url string, data url.Values) (resp *http.Response, err error) {
return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
}

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

0 comments on commit b7f0076

Please sign in to comment.