MCPcopy Create free account
hub / github.com/anchordotdev/cli / post

Method post

api/api.go:373–402  ·  view source on GitHub ↗
(ctx context.Context, path string, in, out any)

Source from the content-addressed store, hash-verified

371}
372
373func (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
404type basicAuther struct {
405 http.RoundTripper

Callers 5

AttachServiceMethod · 0.95
CreateEABMethod · 0.95
CreateOrgMethod · 0.95
CreateServiceMethod · 0.95
GenerateUserFlowCodesMethod · 0.95

Calls 4

StatusCodeErrorTypeAlias · 0.85
EncodeMethod · 0.80
SetMethod · 0.80
GetMethod · 0.80

Tested by

no test coverage detected