From 145973078dd959850e97b5ae7847f96a07ea06d6 Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Sun, 21 Aug 2022 07:50:35 -0700 Subject: [PATCH] implement Post for the custom http client --- pkg/httpclient/client.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/httpclient/client.go b/pkg/httpclient/client.go index c2c2c085..95598b11 100644 --- a/pkg/httpclient/client.go +++ b/pkg/httpclient/client.go @@ -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). @@ -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) }