Documentation
¶
Overview ¶
Package render turns a (masked) product result into the text an agent sees, within the caps of a profile: a table (TSV or JSON) or any typed JSON value. Control and bidirectional characters are escaped, invalid UTF-8 is replaced, NULL is "NULL" (null in JSON), binary values are "<bytes:N>" and times ISO 8601.
Cells are cut while they are converted, so a huge value never costs more than its cap in output.
Index ¶
Constants ¶
const ( FormatTSV = "tsv" FormatJSON = "json" )
Formats.
Variables ¶
var DefaultCaps = Caps{MaxRows: 200, MaxCellChars: 200, MaxOutputBytes: 65_536}
DefaultCaps are the caps of an unset field.
var ErrOutputCap = errors.New("render: the result is over the output cap")
ErrOutputCap means a value encodes to more than Caps.MaxOutputBytes: nothing is written. The product pages or narrows its result.
Functions ¶
func Render ¶
Render writes t to w in format "tsv" (the default when empty) or "json". Rows beyond MaxRows are dropped and reported as truncated; rows that would push the output past MaxOutputBytes are dropped with a marker.
func Text ¶
Text is the display form of a non-nil value: bytes as <bytes:N>, times in RFC 3339, floats with NaN and ±Infinity spelled out.
func Value ¶
Value writes v as one line of JSON: every string, object keys included, escaped and cut at Caps.MaxCellChars characters (as a table cell in JSON mode); numbers, booleans and nulls keep their JSON type. The output is at most Caps.MaxOutputBytes, or ErrOutputCap and nothing written. MaxRows does not apply: a product bounds its own lists.
Types ¶
type Caps ¶
type Caps struct {
MaxRows int
MaxCellChars int
MaxOutputBytes int
// CutNote is the footer line that tells how many cells were cut; nil
// gives the default wording.
CutNote func(cells, maxChars int) string
}
Caps bound an output. Zero or negative fields take the defaults (DefaultCaps).
type Cells ¶
Cells is the TSV rendering of a table split into cells, with the same caps as Render: the header labels, the rows shown and the lines after them (cut marker, row count).
type Table ¶
type Table struct {
Columns []string
Rows [][]any
Truncated bool // more rows exist beyond the producer's own cap
Affected int64
// Cut marks the cells (row, column) the producer already cut while
// reading them; they count in the cut-cells note.
Cut map[[2]int]bool
}
Table is a tabular result: column labels and rows of values. A table without columns reports Affected rows instead (a write).