fix requests

nats
Paulo Simão 2021-10-10 13:15:15 -03:00
parent e0a0904c90
commit 42df57854b
1 changed files with 10 additions and 9 deletions

View File

@ -41,15 +41,10 @@ func (c *Cli) HttpDo(method string, strurl string, body []byte) (*http.Response,
} }
strurl = addr + strurl strurl = addr + strurl
} }
req, err := http.NewRequest(method, strurl, bytes.NewReader(body))
if err != nil { var req *http.Request
return nil, err var err error
}
if c.headers != nil {
for k, v := range c.headers {
req.Header.Set(k, v)
}
}
if body != nil && len(body) > 0 { if body != nil && len(body) > 0 {
req, err = http.NewRequest(method, strurl, io.NopCloser(bytes.NewReader(body))) 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 { if err != nil {
return nil, err 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("X-API-KEY", apikey)
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
return c.cli.Do(req) return c.cli.Do(req)