fix body building
parent
508da7f9cb
commit
f0a5dd5025
17
lib.go
17
lib.go
|
@ -39,15 +39,9 @@ func (c *Cli) Do(method string, strurl string, body []byte) (*http.Response, err
|
||||||
}
|
}
|
||||||
strurl = addr + strurl
|
strurl = addr + strurl
|
||||||
}
|
}
|
||||||
req, err := http.NewRequest(method, strurl, bytes.NewReader(body))
|
var req *http.Request
|
||||||
if err != nil {
|
var err error
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
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)))
|
||||||
|
|
||||||
|
@ -57,6 +51,11 @@ 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
|
||||||
}
|
}
|
||||||
|
if c.headers != nil {
|
||||||
|
for k, v := range c.headers {
|
||||||
|
req.Header.Set(k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
return c.cli.Do(req)
|
return c.cli.Do(req)
|
||||||
}
|
}
|
||||||
func (c *Cli) DoJson(method string, strurl string, i interface{}, o interface{}) (err error) {
|
func (c *Cli) DoJson(method string, strurl string, i interface{}, o interface{}) (err error) {
|
||||||
|
|
Loading…
Reference in New Issue