clihttp

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package clihttp provides shared JSON HTTP transport helpers for CLI commands.

Index

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.

func PutJSON

func PutJSON(ctx context.Context, client *http.Client, url string, body io.Reader, dst any, opts RequestOptions) (*http.Response, error)

PutJSON executes an HTTP PUT with an optional JSON body and decodes JSON into dst when the response status is 200 OK.

func PutJSONCreated

func PutJSONCreated(ctx context.Context, client *http.Client, url string, body io.Reader, dst any, opts RequestOptions) (*http.Response, error)

PutJSONCreated executes an HTTP PUT with an optional JSON body and decodes JSON into dst when the response status is 201 Created.

Types

type RequestOptions

type RequestOptions struct {
	Diagnostics  io.Writer
	Verbose      bool
	EndpointPath string
	LogLabel     string
}

RequestOptions configures diagnostics for JSON HTTP transport helpers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL