buildRequest builds an HTTP request.
(
method, path string,
body interface{},
urlParams map[string]string,
)
| 112 | |
| 113 | // buildRequest builds an HTTP request. |
| 114 | func (c *Client) buildRequest( |
| 115 | method, path string, |
| 116 | body interface{}, |
| 117 | urlParams map[string]string, |
| 118 | ) (req *http.Request, err error) { |
| 119 | url := DefaultBaseURL + path |
| 120 | |
| 121 | if body == nil { |
| 122 | req, err = c.buildRequestWithoutBody(method, url) |
| 123 | } else { |
| 124 | req, err = c.buildRequestWithBody(method, url, body) |
| 125 | } |
| 126 | |
| 127 | req.SetBasicAuth(c.UserID, c.APIKey) |
| 128 | req.Header.Set("Content-Type", "application/json") |
| 129 | |
| 130 | // Add URL params |
| 131 | values := req.URL.Query() |
| 132 | for k, v := range urlParams { |
| 133 | values.Set(k, v) |
| 134 | } |
| 135 | req.URL.RawQuery = values.Encode() |
| 136 | |
| 137 | return req, err |
| 138 | } |
| 139 | |
| 140 | // unmarshalTo unmarshals an HTTP response body to a given interface. |
| 141 | func unmarshalTo(r *http.Response, v interface{}) error { |
no test coverage detected