(method, endpoint string, body io.Reader, contentType string, requireAuth bool)
| 77 | } |
| 78 | |
| 79 | func (c *Client) doRequest(method, endpoint string, body io.Reader, contentType string, requireAuth bool) (int, []byte, error) { |
| 80 | req, err := http.NewRequest(method, endpoint, body) |
| 81 | if err != nil { |
| 82 | return 0, nil, err |
| 83 | } |
| 84 | if contentType != "" { |
| 85 | req.Header.Set("Content-Type", contentType) |
| 86 | } |
| 87 | if requireAuth { |
| 88 | if err := c.authHeaders(req); err != nil { |
| 89 | return 0, nil, err |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | resp, err := c.http.Do(req) |
| 94 | if err != nil { |
| 95 | return 0, nil, err |
| 96 | } |
| 97 | defer resp.Body.Close() |
| 98 | |
| 99 | data, err := io.ReadAll(resp.Body) |
| 100 | if err != nil { |
| 101 | return 0, nil, err |
| 102 | } |
| 103 | return resp.StatusCode, data, nil |
| 104 | } |
| 105 | |
| 106 | func (c *Client) get(endpoint string, requireAuth bool) (int, []byte, error) { |
| 107 | return c.doRequest(http.MethodGet, endpoint, nil, "", requireAuth) |
no test coverage detected