(ctx context.Context, path string, body, out any)
| 146 | } |
| 147 | |
| 148 | func (c *Client) post(ctx context.Context, path string, body, out any) error { |
| 149 | b, err := json.Marshal(body) |
| 150 | if err != nil { |
| 151 | return err |
| 152 | } |
| 153 | u := c.url |
| 154 | u.Path = path |
| 155 | req, err := http.NewRequestWithContext(ctx, "POST", u.String(), bytes.NewReader(b)) |
| 156 | if err != nil { |
| 157 | return err |
| 158 | } |
| 159 | req.Header.Set("Content-Type", "application/json") |
| 160 | res, err := http.DefaultClient.Do(req) |
| 161 | if err != nil { |
| 162 | return err |
| 163 | } |
| 164 | defer res.Body.Close() |
| 165 | if res.StatusCode < 200 || res.StatusCode > 299 { |
| 166 | return parseError(res.Body) |
| 167 | } |
| 168 | return json.NewDecoder(res.Body).Decode(out) |
| 169 | } |
| 170 | |
| 171 | func parseError(body io.Reader) error { |
| 172 | var aerr APIError |
no test coverage detected