helper function to make an http request.
(ctx context.Context, rawurl, method string, noToken bool, in, out interface{})
| 169 | |
| 170 | // helper function to make an http request. |
| 171 | func (c *HTTPClient) do(ctx context.Context, rawurl, method string, noToken bool, in, out interface{}) error { |
| 172 | // executes the http request and returns the body as |
| 173 | // and io.ReadCloser |
| 174 | body, err := c.stream(ctx, rawurl, method, noToken, in, out) |
| 175 | if body != nil { |
| 176 | defer func(body io.ReadCloser) { |
| 177 | _ = body.Close() |
| 178 | }(body) |
| 179 | } |
| 180 | if err != nil { |
| 181 | return err |
| 182 | } |
| 183 | |
| 184 | // if a json response is expected, parse and return |
| 185 | // the json response. |
| 186 | if out != nil { |
| 187 | return json.NewDecoder(body).Decode(out) |
| 188 | } |
| 189 | return nil |
| 190 | } |
| 191 | |
| 192 | // helper function to stream a http request. |
| 193 | func (c *HTTPClient) stream(ctx context.Context, rawurl, method string, noToken bool, |