Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decod
(req *http.Request, v any)
| 1326 | // If rate limit is exceeded and reset time is in the future, Do returns |
| 1327 | // *RateLimitError immediately without making a network API call. |
| 1328 | func (c *Client) Do(req *http.Request, v any) (*Response, error) { |
| 1329 | resp, err := c.BareDo(req) |
| 1330 | if err != nil { |
| 1331 | return resp, err |
| 1332 | } |
| 1333 | defer resp.Body.Close() |
| 1334 | |
| 1335 | switch v := v.(type) { |
| 1336 | case nil: |
| 1337 | case io.Writer: |
| 1338 | _, err = io.Copy(v, resp.Body) |
| 1339 | default: |
| 1340 | decErr := json.NewDecoder(resp.Body).Decode(v) |
| 1341 | if decErr == io.EOF { |
| 1342 | decErr = nil // ignore EOF errors caused by empty response body |
| 1343 | } |
| 1344 | if decErr != nil { |
| 1345 | err = decErr |
| 1346 | } |
| 1347 | } |
| 1348 | return resp, err |
| 1349 | } |
| 1350 | |
| 1351 | // checkRateLimitBeforeDo does not make any network calls, but uses existing knowledge from |
| 1352 | // current client state in order to quickly check if *RateLimitError can be immediately returned |