client

package
v0.8.9 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, c *Client) context.Context

NewContext stores the client in the given context and returns the new context.

func QueryFromFlags

func QueryFromFlags(cmd *cobra.Command, names ...string) url.Values

QueryFromFlags extracts only the flags from names that have actually been changed by the user (i.e. are "set" in the flag set) and returns them as url.Values.

Types

type Client

type Client struct {
	BaseURL    string
	Auth       config.AuthConfig
	HTTPClient *http.Client
	Stdout     io.Writer     // JSON responses go here
	Stderr     io.Writer     // structured errors go here
	JQFilter   string        // --jq filter expression
	Paginate   bool          // auto-paginate GET responses
	DryRun     bool          // output request as JSON, don't execute
	Verbose    bool          // log request/response to stderr
	Pretty     bool          // pretty-print JSON
	Fields     string        // --fields comma-separated field names for GET
	CacheTTL   time.Duration // --cache duration; 0 means no caching
}

Client is the core HTTP client for jr. It wraps net/http with auth, pagination, jq filtering, and structured error output.

func FromContext

func FromContext(ctx context.Context) (*Client, error)

FromContext retrieves the Client stored in ctx. Returns an error if no client was stored.

func (*Client) ApplyAuth added in v0.4.0

func (c *Client) ApplyAuth(req *http.Request)

ApplyAuth sets authentication headers on the request according to the client's Auth configuration.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, query url.Values, body io.Reader) int

Do executes an HTTP request and returns an exit code. It constructs the URL from BaseURL+path+query, applies auth, handles pagination, jq filtering, and pretty-printing. Errors are written as structured JSON to Stderr.

func (*Client) VerboseLog added in v0.8.2

func (c *Client) VerboseLog(fields map[string]any)

VerboseLog writes a structured JSON log entry to stderr when verbose mode is enabled.

Jump to

Keyboard shortcuts

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