output

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFilter    = errors.New("invalid filter: expected key=value")
	ErrUnknownFilterKey = errors.New("unknown filter key")
)

Sentinel errors for filter parsing.

Functions

func ApplyFilters

func ApplyFilters(data any, filters []string) (any, error)

ApplyFilters filters a slice of structs by key=value pairs. Keys are matched against table/json struct tags (case-insensitive). Values use case-insensitive substring matching. Multiple filters are AND-ed together. Empty filters returns data unchanged.

Types

type Formatter

type Formatter interface {
	// Format writes the data to the writer in the formatter's format.
	Format(w io.Writer, data any) error
}

Formatter defines the interface for output formatting.

func NewFormatter

func NewFormatter(format string) Formatter

NewFormatter creates a Formatter for the given format string.

type JSONFormatter

type JSONFormatter struct{}

JSONFormatter outputs data as pretty-printed JSON.

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(w io.Writer, data any) error

Format writes the data as indented JSON.

type TableFormatter

type TableFormatter struct{}

TableFormatter outputs data as an aligned table using text/tabwriter.

func (*TableFormatter) Format

func (f *TableFormatter) Format(w io.Writer, data any) error

Format renders the data as a formatted table. Data should be a slice of structs or a single struct. Struct field tags control headers. Fields with table:"-" are skipped.

type YAMLFormatter

type YAMLFormatter struct{}

YAMLFormatter outputs data as YAML.

func (*YAMLFormatter) Format

func (f *YAMLFormatter) Format(w io.Writer, data any) error

Format writes the data as YAML.

Jump to

Keyboard shortcuts

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