formatter

package
v0.4.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorDetail

type ErrorDetail struct {
	Message string                 `json:"message"`
	Code    string                 `json:"code,omitempty"`
	Details map[string]interface{} `json:"details,omitempty"`
}

ErrorDetail contains the details of an error.

type ErrorFormatter

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

ErrorFormatter formats errors as structured JSON output.

func NewErrorFormatter

func NewErrorFormatter(out io.Writer) *ErrorFormatter

NewErrorFormatter creates a new ErrorFormatter for formatting error output.

func (*ErrorFormatter) Format

func (f *ErrorFormatter) Format(data interface{}) error

Format marshals error data to JSON and writes it to the output writer.

type ErrorResponse

type ErrorResponse struct {
	Error ErrorDetail `json:"error"`
}

ErrorResponse represents a structured error response.

type Formatter

type Formatter interface {
	// Format takes data and writes it to the output writer in the desired format.
	Format(data interface{}) error
}

Formatter defines the interface for formatting output data.

func New

func New(format OutputFormat, out io.Writer) Formatter

New creates a new Formatter for the specified format and output writer.

type JSONFormatter

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

JSONFormatter formats output as JSON.

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(data interface{}) error

Format marshals data to JSON and writes it to the output writer.

type ListResponse

type ListResponse struct {
	Items []interface{} `json:"items"`
	Total int           `json:"total"`
}

ListResponse represents a structured list response with metadata.

type OutputFormat

type OutputFormat string

OutputFormat represents the output format type.

const (
	// JSONFormat outputs data as formatted JSON.
	JSONFormat OutputFormat = "json"
	// TableFormat outputs data as an aligned table.
	TableFormat OutputFormat = "table"
	// PlainFormat outputs data in a minimal format suitable for scripting.
	PlainFormat OutputFormat = "plain"
)

type PlainFormatter

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

PlainFormatter formats output as plain text suitable for scripting.

func (*PlainFormatter) Format

func (f *PlainFormatter) Format(data interface{}) error

Format converts data to plain format and writes it to the output writer. Plain format outputs minimal text, one value per line, suitable for shell variables.

type StreamingFormatter

type StreamingFormatter interface {
	// FormatStream takes a channel of items and writes them progressively to the output.
	// The formatter should consume items from the channel and output them incrementally.
	FormatStream(items chan interface{}) error
}

StreamingFormatter defines the interface for streaming output with progressive rendering.

func NewStreaming

func NewStreaming(format OutputFormat, out io.Writer) StreamingFormatter

NewStreaming creates a new StreamingFormatter for the specified format and output writer.

type StreamingJSONFormatter

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

StreamingJSONFormatter formats output as newline-delimited JSON (NDJSON).

func (*StreamingJSONFormatter) FormatStream

func (f *StreamingJSONFormatter) FormatStream(items chan interface{}) error

FormatStream outputs each item as a JSON object on a separate line.

type StreamingPlainFormatter

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

StreamingPlainFormatter formats output as plain text with progressive rendering.

func (*StreamingPlainFormatter) FormatStream

func (f *StreamingPlainFormatter) FormatStream(items chan interface{}) error

FormatStream outputs each item's first value on a separate line.

type StreamingTableFormatter

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

StreamingTableFormatter formats output as an aligned table with progressive rendering.

func (*StreamingTableFormatter) FormatStream

func (f *StreamingTableFormatter) FormatStream(items chan interface{}) error

FormatStream outputs items as table rows progressively using StreamingTablePrinter.

type TableFormatter

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

TableFormatter formats output as an aligned table.

func (*TableFormatter) Format

func (f *TableFormatter) Format(data interface{}) error

Format converts data to table format and writes it to the output writer.

Jump to

Keyboard shortcuts

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