Documentation ¶
Overview ¶
Package output contains helpers for emitting structure JSON output.
Index ¶
- func JSON(sink *Sink, obj any) error
- func List[T proto.Message](sink *Sink, items []T) error
- func ListEntry[T proto.Message](sink *Sink, entry T) error
- func Map[T proto.Message](sink *Sink, items map[string]T) error
- func MapEntry[T proto.Message](sink *Sink, key string, entry T) error
- func Proto(sink *Sink, msg proto.Message) error
- func StartList(sink *Sink) error
- func StartMap(sink *Sink) error
- type Sink
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSON ¶
JSON writes a single JSON-marshallable object as the entire output.
It uses the standard Go library JSON encoder to serialize it.
func List ¶
List writes a JSON list where each item is a proto message.
This is a helper that just calls StartList and ListEntry.
func ListEntry ¶
ListEntry writes a single list entry to the output.
It can be called multiple times to write many entries one by one.
func Map ¶
Map writes a JSON map where each item is a proto message.
This is a helper that just calls StartMap and MapEntry. Sorts map entries by key.
func MapEntry ¶
MapEntry writes a single map entry to the output.
It can be called multiple times to write many entries one by one.
func Proto ¶
Proto writes a single protobuf message as the entire output.
It uses protojson encoding to serialize it.
Types ¶
type Sink ¶
type Sink struct {
// contains filtered or unexported fields
}
Sink is what eventually receives the output.
Safe for concurrent use.
func NewDiscardingSink ¶
func NewDiscardingSink() *Sink
NewDiscardingSink returns a sink that just quickly discards all writes.