Add SetCli, Remove defer body.close from Do

master
Paulo Simão 2021-10-31 06:35:05 -03:00
parent 45fd265264
commit ecf33aed8a
1 changed files with 3 additions and 1 deletions

4
lib.go
View File

@ -16,6 +16,9 @@ type Cli struct {
basePath string basePath string
} }
func (c *Cli) SetCli(h *http.Client) {
c.cli = h
}
func (c *Cli) BasePath() string { func (c *Cli) BasePath() string {
return c.basePath return c.basePath
} }
@ -60,7 +63,6 @@ func (c *Cli) Do(method string, strurl string, body []byte) (*http.Response, err
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
if res.StatusCode >= 400 { if res.StatusCode >= 400 {
return nil, errors.New(fmt.Sprintf("Http return code - %d: %s", res.StatusCode, res.Status)) return nil, errors.New(fmt.Sprintf("Http return code - %d: %s", res.StatusCode, res.Status))
} }