output

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package output renders responses and diagnostics, and owns the exit-code contract.

Index

Constants

View Source
const (
	ExitOK        = 0 // 2xx
	ExitInternal  = 1 // unexpected internal error
	ExitUsage     = 2 // bad flags, missing required param, unknown operation
	ExitConfig    = 3 // no config file, bad env, malformed TOML
	ExitAuth      = 4 // 401/403, or credential resolution failed
	ExitBlocked   = 5 // blocked by a safety rule
	ExitTransport = 6 // DNS, connection refused, timeout, TLS
	ExitClient    = 7 // 4xx other than 401/403
	ExitServer    = 8 // 5xx
	ExitSchema    = 9 // response did not match the spec schema, under --strict
)

The exit-code contract. A caller branches on these, so they never change meaning.

View Source
const (
	ModeJSON   = "json"
	ModeRaw    = "raw"
	ModeStatus = "status"
)

Output modes.

View Source
const MinSecretLength = 8

MinSecretLength is the shortest value worth substituting. Anything shorter matches so much unrelated text that the output stops being reviewable, and the pattern of holes leaks the value it was hiding.

View Source
const Placeholder = "<redacted>"

Placeholder is what replaces a secret in any output blip produces.

Variables

This section is empty.

Functions

func Authf

func Authf(format string, args ...any) error

func Blockedf

func Blockedf(format string, args ...any) error

func Configf

func Configf(format string, args ...any) error

func ExitCodeFor

func ExitCodeFor(err error) int

ExitCodeFor reports the exit code for err. An untagged error is a bug in blip, not a predictable failure, so it maps to ExitInternal.

func ExitCodeForStatus

func ExitCodeForStatus(status int) int

ExitCodeForStatus maps an HTTP status onto blip's exit-code contract. Anything that is not 2xx, 401, 403 or 5xx is reported as a client error, including a 3xx that survived redirect handling.

func FirstLine added in v0.2.0

func FirstLine(s string) string

FirstLine keeps a multi-line message out of a single-line diagnostic.

func Silent

func Silent(code int) error

Silent carries an exit code with nothing left to say, for when the failure has already been reported in full: a 404 body is the message, and "blip: error" on top of it is noise.

func Usagef

func Usagef(format string, args ...any) error

Constructors for the coded errors, so that every package tags failures the same way and the contract stays readable from this one file.

func ValidateMode

func ValidateMode(mode string) error

ValidateMode rejects an unknown --output value.

func WithCode

func WithCode(err error, code int) error

WithCode tags err with the exit code blip should terminate with.

Types

type Redactor

type Redactor struct {
	// contains filtered or unexported fields
}

Redactor keeps secrets out of verbose and dry-run output.

func NewRedactor

func NewRedactor(secrets []string, extraHeaders ...string) *Redactor

NewRedactor redacts the always-secret headers, any extra header the profile names, and the literal secret values themselves wherever they appear.

func (*Redactor) Header

func (r *Redactor) Header(h http.Header) http.Header

Header returns a copy of h with every value redacted.

func (*Redactor) HeaderValue

func (r *Redactor) HeaderValue(name, value string) string

HeaderValue redacts a header value, keeping the auth scheme visible because knowing it is Bearer rather than Basic is diagnostic, not secret.

func (*Redactor) String

func (r *Redactor) String(s string) string

String replaces any known secret value wherever it appears.

type Renderer

type Renderer struct {
	Mode           string
	Pretty         bool
	IncludeHeaders bool
	Stdout         io.Writer
	Stderr         io.Writer
	Redactor       *Redactor
}

Renderer writes a response according to the output contract: body on stdout, everything else on stderr.

func (*Renderer) DryRun

func (r *Renderer) DryRun(method, url, envName string, header http.Header, body []byte) error

DryRun renders a request without sending it. The format is a contract an agent reads, so it stays stable: request line, environment, headers, blank line, body.

func (*Renderer) Response

func (r *Renderer) Response(status int, header http.Header, body []byte) error

Response writes the response. Error bodies are written just like any other, so the API's own error payload survives.

func (*Renderer) Summary

func (r *Renderer) Summary(method, url string, status int)

Summary is the one-line stderr note that accompanies a non-2xx response.

Jump to

Keyboard shortcuts

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