From 42df57854b93afa9f957aa0c6b1387373b83d015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20Sima=CC=83o?= Date: Sun, 10 Oct 2021 13:15:15 -0300 Subject: [PATCH] fix requests --- api/cli.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/api/cli.go b/api/cli.go index 860e853..070807c 100644 --- a/api/cli.go +++ b/api/cli.go @@ -41,15 +41,10 @@ func (c *Cli) HttpDo(method string, strurl string, body []byte) (*http.Response, } strurl = addr + strurl } - req, err := http.NewRequest(method, strurl, bytes.NewReader(body)) - if err != nil { - return nil, err - } - if c.headers != nil { - for k, v := range c.headers { - req.Header.Set(k, v) - } - } + + var req *http.Request + var err error + if body != nil && len(body) > 0 { req, err = http.NewRequest(method, strurl, io.NopCloser(bytes.NewReader(body))) @@ -59,6 +54,12 @@ func (c *Cli) HttpDo(method string, strurl string, body []byte) (*http.Response, if err != nil { return nil, err } + if c.headers != nil { + for k, v := range c.headers { + req.Header.Set(k, v) + } + } + req.Header.Set("X-API-KEY", apikey) req.Header.Set("Content-Type", "application/json") return c.cli.Do(req)