Documentation
¶
Index ¶
- 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 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 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 StreamingFormatter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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 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
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 FormatMsgPack ¶ added in v0.12.0
FormatMsgPack formats the provided raw MessagePack data to the Printer as JSON.
func FormatNDJSON ¶ added in v0.5.0
FormatNDJSON streams the provided newline-delimited JSON to the Printer, flushing every line.
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 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.