(ctx context.Context, path string, in, out any)
| 371 | } |
| 372 | |
| 373 | func (s *Session) post(ctx context.Context, path string, in, out any) error { |
| 374 | var buf bytes.Buffer |
| 375 | if in != nil { |
| 376 | if err := json.NewEncoder(&buf).Encode(in); err != nil { |
| 377 | return err |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | req, err := http.NewRequestWithContext(ctx, "POST", path, &buf) |
| 382 | if err != nil { |
| 383 | return err |
| 384 | } |
| 385 | if in != nil { |
| 386 | req.Header.Set("Content-Type", "application/json") |
| 387 | } |
| 388 | |
| 389 | res, err := s.Do(req) |
| 390 | if err != nil { |
| 391 | return err |
| 392 | } |
| 393 | if res.StatusCode != http.StatusOK { |
| 394 | var errorsRes *Error |
| 395 | if err = json.NewDecoder(res.Body).Decode(&errorsRes); err != nil { |
| 396 | return err |
| 397 | } |
| 398 | requestId := res.Header.Get("X-Request-Id") |
| 399 | return fmt.Errorf("request [%s]: %w: %s", requestId, StatusCodeError(res.StatusCode), errorsRes.Title) |
| 400 | } |
| 401 | return json.NewDecoder(res.Body).Decode(out) |
| 402 | } |
| 403 | |
| 404 | type basicAuther struct { |
| 405 | http.RoundTripper |
no test coverage detected