contract

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	AuthRequired    = "AUTH_REQUIRED"
	AuthInvalid     = "AUTH_INVALID"
	NotFound        = "NOT_FOUND"
	ValidationError = "VALIDATION_ERROR"
	Conflict        = "CONFLICT"
	RateLimited     = "RATE_LIMITED"
	HTTPError       = "HTTP_ERROR"
	FileNotFound    = "FILE_NOT_FOUND"
	Unsupported     = "UNSUPPORTED"
	UnknownError    = "UNKNOWN_ERROR"
)

Variables

This section is empty.

Functions

func ErrorEnvelope

func ErrorEnvelope(code, message string) ([]byte, error)

ErrorEnvelope builds a JSON error envelope from a code and message.

func ErrorFromContractError

func ErrorFromContractError(ce *ContractError) ([]byte, error)

ErrorFromContractError builds a JSON error envelope from a ContractError.

func NewError

func NewError(code, message string) error

NewError creates a new ContractError.

func Render

func Render(w io.Writer, envelope []byte, pretty bool) error

Render writes a JSON envelope to the writer. If pretty is true, output is indented.

func RequireAtLeastOne

func RequireAtLeastOne(flags map[string]string) error

RequireAtLeastOne returns a VALIDATION_ERROR if no flags have a non-empty value.

func RequireExactlyOne

func RequireExactlyOne(flags map[string]string) error

RequireExactlyOne returns a VALIDATION_ERROR if not exactly one flag has a non-empty value.

func RequireFlag

func RequireFlag(name, value string) error

RequireFlag returns a VALIDATION_ERROR if value is empty.

func Success

func Success(data any) ([]byte, error)

Success builds a JSON success envelope.

func ValidateFilePath

func ValidateFilePath(path string) error

ValidateFilePath returns a FILE_NOT_FOUND if the path is empty or does not exist.

func ValidateISO8601

func ValidateISO8601(value string) error

ValidateISO8601 returns a VALIDATION_ERROR if the value is not a valid ISO-8601 date.

func ValidateISO8601Optional

func ValidateISO8601Optional(value string) error

ValidateISO8601Optional validates an ISO-8601 date only if non-empty.

func ValidateURL

func ValidateURL(value string) error

ValidateURL returns a VALIDATION_ERROR if the value is not a valid HTTP(S) URL.

Types

type ContractError

type ContractError struct {
	Code    string
	Message string
}

ContractError represents a structured CLI error with a machine-readable code.

func (*ContractError) Error

func (e *ContractError) Error() string

Jump to

Keyboard shortcuts

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