summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/monaco-io/request/request.go
blob: 6eb45acfc5dc93671bd32924c8095ab98390c894 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package request

import (
	"io/ioutil"
	"net/http"
)

// Do send http request
func (c *Client) Do() (resp SugaredResp, err error) {
	defer resp.Close()

	if err = c.buildRequest(); err != nil {
		return
	}

	// send request and close on func call end
	if resp.resp, err = c.client.Do(c.req); err != nil {
		return
	}

	// read response data form resp
	resp.Data, err = ioutil.ReadAll(resp.resp.Body)
	resp.Code = resp.resp.StatusCode
	return
}

// Resp do request and get original http response struct
func (c *Client) Resp() (resp *http.Response, err error) {
	if err = c.buildRequest(); err != nil {
		return
	}
	return c.client.Do(c.req)
}