format

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatCSS added in v0.16.0

func FormatCSS(buf []byte, p *core.Printer) error

FormatCSS formats the provided CSS to the Printer.

func FormatCSSIndented added in v0.16.0

func FormatCSSIndented(buf []byte, p *core.Printer, baseIndent int) error

FormatCSSIndented formats CSS with a base indentation level. Used for formatting CSS embedded in HTML <style> tags.

func FormatCSV added in v0.16.0

func FormatCSV(buf []byte, p *core.Printer) error

FormatCSV formats the provided CSV data to the Printer.

func FormatEventStream added in v0.6.0

func FormatEventStream(r io.Reader, p *core.Printer) error

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 a gRPC response stream by reading and formatting each length-prefixed frame as it arrives. This handles both unary (single frame) and server-streaming (multiple frames) responses.

func FormatHTML added in v0.16.0

func FormatHTML(buf []byte, w *core.Printer) error

FormatHTML formats the provided HTML to the Printer.

func FormatJSON

func FormatJSON(buf []byte, p *core.Printer) error

FormatJSON formats the provided raw JSON data to the Printer.

func FormatJSONLine added in v0.19.0

func FormatJSONLine(buf []byte, p *core.Printer) error

FormatJSONLine formats the provided raw JSON data as a single compact line to the Printer.

func FormatMarkdown added in v0.20.0

func FormatMarkdown(buf []byte, p *core.Printer) error

FormatMarkdown formats the provided Markdown to the Printer.

func FormatMsgPack added in v0.12.0

func FormatMsgPack(buf []byte, p *core.Printer) error

FormatMsgPack formats the provided raw MessagePack data to the Printer as JSON.

func FormatNDJSON added in v0.5.0

func FormatNDJSON(r io.Reader, p *core.Printer) error

FormatNDJSON streams the provided newline-delimited JSON to the Printer, flushing every line.

func FormatProtobuf added in v0.16.0

func FormatProtobuf(buf []byte, p *core.Printer) error

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.

func FormatXML

func FormatXML(buf []byte, w *core.Printer) error

FormatXML formats the provided XML to the Printer.

func FormatYAML added in v0.18.0

func FormatYAML(buf []byte, p *core.Printer) error

FormatYAML formats the provided raw YAML data to the Printer.

Types

type BufferedFormatter added in v0.20.0

type BufferedFormatter func(buf []byte, p *core.Printer) error

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 StreamingFormatter added in v0.20.0

type StreamingFormatter func(r io.Reader, p *core.Printer) error

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.

Jump to

Keyboard shortcuts

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