Documentation
¶
Overview ¶
Package render provides helpers for writing structured output (table, JSON, YAML) to io.Writer. The preferred path for tabular output is the TableRenderable interface; a convenience container TableData is provided for ad-hoc multi-row tables. Unknown value types fall back to YAML.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Render ¶
Render serialises obj in the requested format and writes it to the provided io.Writer.
Table-format rules:
- If obj implements TableRenderable, its methods drive the output.
- If obj is a plain struct (or pointer to one) it is rendered as FIELD/VALUE rows.
- Anything else falls back to YAML.
Types ¶
type Option ¶
type Option func(*options)
Option is a functional option for Render.
func WithNoHeaders ¶
func WithNoHeaders() Option
WithNoHeaders suppresses column headers when rendering in table format.
type TableData ¶
type TableData struct {
// Headers is the ordered list of column names.
Headers []string
// Rows is the ordered list of data rows; each row must align with Headers.
Rows [][]string
}
TableData is a concrete, self-contained table that implements TableRenderable. Use it when you have pre-built header/row data and do not need a custom type.
Example:
td := render.TableData{
Headers: []string{"NAME", "AGE"},
Rows: [][]string{{"Alice", "30"}, {"Bob", "25"}},
}
render.Render(ctx, td, render.FormatTable)
func (TableData) TableHeaders ¶
TableHeaders implements TableRenderable.
type TableRenderable ¶
type TableRenderable interface {
// TableHeaders returns the ordered column names for the table header row.
TableHeaders() []string
// TableRows returns the ordered data rows; each inner slice must align with
// the slice returned by TableHeaders.
TableRows() [][]string
}
TableRenderable is the explicit public interface for custom tabular rendering. Implement TableHeaders and TableRows on your domain or view type to control exactly how it appears in table output.
For ad-hoc multi-row tables without a custom type, use TableData.