Documentation
¶
Index ¶
- Variables
- func FormatCSS(buf []byte, p *core.Printer) error
- func FormatCSSIndented(buf []byte, p *core.Printer, baseIndent int) error
- func FormatCSV(buf []byte, p *core.Printer) error
- func FormatEventStream(r io.Reader, p *core.Printer) error
- func FormatGRPCStream(r io.Reader, md protoreflect.MessageDescriptor, p *core.Printer) error
- func FormatGRPCStreamWithEncoding(r io.Reader, md protoreflect.MessageDescriptor, p *core.Printer, ...) error
- func FormatHTML(buf []byte, w *core.Printer) error
- func FormatJSON(buf []byte, p *core.Printer) error
- func FormatJSONLine(buf []byte, p *core.Printer) error
- func FormatMarkdown(buf []byte, p *core.Printer) error
- func FormatMarkdownWithOptions(buf []byte, p *core.Printer, options MarkdownOptions) error
- func FormatMsgPack(buf []byte, p *core.Printer) error
- func FormatNDJSON(r io.Reader, p *core.Printer) error
- func FormatProtobuf(buf []byte, p *core.Printer) error
- func FormatProtobufWithDescriptor(buf []byte, md protoreflect.MessageDescriptor, p *core.Printer) error
- func FormatProtobufWithSchema(buf []byte, schema *fetchproto.Schema, typeName string, p *core.Printer) error
- func FormatXML(buf []byte, w *core.Printer) error
- func FormatYAML(buf []byte, p *core.Printer) error
- type BufferedFormatter
- type ContentType
- type MarkdownOptions
- type StreamingFormatter
Constants ¶
This section is empty.
Variables ¶
var ErrStreamingLimit = errors.New("streaming record limit exceeded")
Functions ¶
func FormatCSSIndented ¶ added in v0.16.0
FormatCSSIndented formats CSS with a base indentation level. Used for formatting CSS embedded in HTML <style> tags.
func FormatEventStream ¶ added in v0.6.0
FormatEventStream formats the provided stream of server sent events to the Printer, flushing after each event.
func FormatGRPCStream ¶ added in v0.17.0
func FormatGRPCStream(r io.Reader, md protoreflect.MessageDescriptor, p *core.Printer) error
FormatGRPCStream formats an uncompressed gRPC response stream by reading and formatting each length-prefixed frame as it arrives. It is retained for callers that do not have response metadata; compressed frames are rejected with an actionable missing-encoding error.
func FormatGRPCStreamWithEncoding ¶ added in v0.28.0
func FormatGRPCStreamWithEncoding(r io.Reader, md protoreflect.MessageDescriptor, p *core.Printer, encoding string) error
FormatGRPCStreamWithEncoding formats a gRPC response stream incrementally. The grpc-encoding value applies to frames whose compressed flag is set.
func FormatHTML ¶ added in v0.16.0
FormatHTML formats the provided HTML to the Printer.
func FormatJSON ¶
FormatJSON formats the provided raw JSON data to the Printer.
func FormatJSONLine ¶ added in v0.19.0
FormatJSONLine formats the provided raw JSON data as a single compact line to the Printer.
func FormatMarkdown ¶ added in v0.20.0
FormatMarkdown formats the provided Markdown to the Printer.
func FormatMarkdownWithOptions ¶ added in v0.28.0
func FormatMarkdownWithOptions(buf []byte, p *core.Printer, options MarkdownOptions) error
FormatMarkdownWithOptions formats the provided Markdown to the Printer using the supplied terminal presentation options.
func FormatMsgPack ¶ added in v0.12.0
FormatMsgPack formats the provided raw MessagePack data to the Printer as JSON.
MessagePack map keys are not restricted to strings, unlike JSON object keys. This parser converts the supported scalar key types to their JSON string representation before formatting. Binary keys use base64 so arbitrary bytes remain representable. It also validates strings itself so malformed strings produce a parser error before JSON formatting.
func FormatNDJSON ¶ added in v0.5.0
FormatNDJSON streams newline-delimited JSON to the Printer, flushing after each record. It uses explicit line boundaries so a partial record never causes the decoder to retain an unbounded stream prefix.
func FormatProtobuf ¶ added in v0.16.0
FormatProtobuf formats the provided raw protobuf data to the Printer.
func FormatProtobufWithDescriptor ¶ added in v0.16.0
func FormatProtobufWithDescriptor(buf []byte, md protoreflect.MessageDescriptor, p *core.Printer) error
FormatProtobufWithDescriptor formats protobuf data as JSON using a message descriptor.
func FormatProtobufWithSchema ¶ added in v0.16.0
func FormatProtobufWithSchema(buf []byte, schema *fetchproto.Schema, typeName string, p *core.Printer) error
FormatProtobufWithSchema formats protobuf data as JSON using the provided schema.
Types ¶
type BufferedFormatter ¶ added in v0.20.0
BufferedFormatter formats buffered bytes to the Printer.
func GetBuffered ¶ added in v0.20.0
func GetBuffered(ct ContentType) BufferedFormatter
GetBuffered returns the buffered formatter for the given content type, or nil.
type ContentType ¶ added in v0.20.0
type ContentType int
ContentType represents a recognized response content type.
const ( TypeUnknown ContentType = iota TypeCSS TypeCSV TypeGRPC TypeHTML TypeImage TypeJSON TypeMarkdown TypeMsgPack TypeNDJSON TypeProtobuf TypeSSE TypeXML TypeYAML )
func GetContentType ¶ added in v0.20.0
func GetContentType(headers http.Header) (ContentType, string)
GetContentType parses the Content-Type header and returns the detected ContentType and charset. Returns TypeUnknown if the type is not recognized.
func SniffContentType ¶ added in v0.20.0
func SniffContentType(buf []byte) ContentType
SniffContentType attempts to detect the content type of the provided bytes by examining the leading bytes of the body. It is used as a fallback when no Content-Type header is present in the HTTP response.
type MarkdownOptions ¶ added in v0.28.0
type MarkdownOptions struct {
MaxWidth int
// RenderImage renders a Markdown image for terminal presentation and
// returns true when it wrote the image. It is ignored for non-terminal
// output. The callback owns image fetching and safety policy.
RenderImage func(destination string) bool
}
MarkdownOptions controls terminal-only Markdown presentation.
MaxWidth is a maximum display width in terminal columns. A zero value uses the smaller of the current terminal width and 100 columns when the destination is a TTY. Non-terminal output remains raw Markdown regardless of this value.
type StreamingFormatter ¶ added in v0.20.0
StreamingFormatter formats a stream to the Printer.
func GetStreaming ¶ added in v0.20.0
func GetStreaming(ct ContentType) StreamingFormatter
GetStreaming returns the streaming formatter for the given content type, or nil.