2020-07-18 07:08:25 -07:00
|
|
|
package request
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Do send http request
|
|
|
|
func (c *Client) Do() (resp SugaredResp, err error) {
|
|
|
|
defer resp.Close()
|
|
|
|
|
2020-08-30 04:49:26 -07:00
|
|
|
if err = c.buildRequest(); err != nil {
|
|
|
|
return
|
2020-07-18 07:08:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// send request and close on func call end
|
|
|
|
if resp.resp, err = c.client.Do(c.req); err != nil {
|
2020-08-30 04:49:26 -07:00
|
|
|
return
|
2020-07-18 07:08:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// read response data form resp
|
|
|
|
resp.Data, err = ioutil.ReadAll(resp.resp.Body)
|
|
|
|
resp.Code = resp.resp.StatusCode
|
2020-08-30 04:49:26 -07:00
|
|
|
return
|
2020-07-18 07:08:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Resp do request and get original http response struct
|
|
|
|
func (c *Client) Resp() (resp *http.Response, err error) {
|
|
|
|
if err = c.buildRequest(); err != nil {
|
2020-08-30 04:49:26 -07:00
|
|
|
return
|
2020-07-18 07:08:25 -07:00
|
|
|
}
|
|
|
|
return c.client.Do(c.req)
|
|
|
|
}
|