Documentation
¶
Overview ¶
Package clihttp provides shared JSON HTTP transport helpers for CLI commands.
Index ¶
- func DecodeAPIError(resp *http.Response) (factoryapi.ErrorResponse, bool)
- func GetJSON(ctx context.Context, client *http.Client, url string, dst any, ...) (*http.Response, error)
- func PostJSON(ctx context.Context, client *http.Client, url string, body io.Reader, dst any, ...) (*http.Response, error)
- func PostJSONCreated(ctx context.Context, client *http.Client, url string, body io.Reader, dst any, ...) (*http.Response, error)
- func PutJSON(ctx context.Context, client *http.Client, url string, body io.Reader, dst any, ...) (*http.Response, error)
- func PutJSONCreated(ctx context.Context, client *http.Client, url string, body io.Reader, dst any, ...) (*http.Response, error)
- type RequestOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeAPIError ¶
func DecodeAPIError(resp *http.Response) (factoryapi.ErrorResponse, bool)
DecodeAPIError decodes a factory API error response when the body includes a message.
func GetJSON ¶
func GetJSON(ctx context.Context, client *http.Client, url string, dst any, opts RequestOptions) (*http.Response, error)
GetJSON executes an HTTP GET and decodes JSON into dst when the response status is 200 OK. On transport failure it logs an unreachable response diagnostic and returns a non-nil error. On other HTTP statuses it logs a status response diagnostic and returns the response with a nil error so callers can map command-specific errors (for example work show 404).
func PostJSON ¶
func PostJSON(ctx context.Context, client *http.Client, url string, body io.Reader, dst any, opts RequestOptions) (*http.Response, error)
PostJSON executes an HTTP POST with an optional JSON body and decodes JSON into dst when the response status is 200 OK.
func PostJSONCreated ¶
func PostJSONCreated(ctx context.Context, client *http.Client, url string, body io.Reader, dst any, opts RequestOptions) (*http.Response, error)
PostJSONCreated executes an HTTP POST with an optional JSON body and decodes JSON into dst when the response status is 201 Created.