Help us shape the future of Go! Take the 2026 Go Developer Survey

render

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
const (
	FormatTSV  = "tsv"
	FormatJSON = "json"
)

Formats.

Variables

View Source
var DefaultCaps = Caps{MaxRows: 200, MaxCellChars: 200, MaxOutputBytes: 65_536}

DefaultCaps are the caps of an unset field.

View Source
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 CapText

func CapText(s string, maxChars int, jsonMode bool) (string, bool)

CapText is capText in JSON mode (true) or TSV mode, and whether it cut s.

func Render

func Render(w io.Writer, t Table, l Caps, format string) error

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

func Text(v any) string

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

func Value(w io.Writer, v any, l Caps) error

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

type Cells struct {
	Header []string
	Rows   [][]string
	Footer []string
}

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).

func TSVCells

func TSVCells(t Table, l Caps) Cells

TSVCells is what Render writes in format tsv for a table with columns, before the cells are joined.

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).

func (*Table) MarkCut

func (t *Table) MarkCut(row, col int)

MarkCut records that the producer cut cell (row, col).

Jump to

Keyboard shortcuts

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