output

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder interface {
	// WithEncoder sets default content-type and PayloadEncoder that serializes
	// objects into io.Writer in that content-type.
	WithEncoder(ct string, encFunc PayloadEncoder) Builder
	// WithErrorMapper registers mapping function that can customize error response
	WithErrorMapper(mapper ErrorMapper) Builder
	// Build creates new Interface using current state of this Builder.
	Build() Interface
}

func NewBuilder

func NewBuilder() Builder

type ErrorMapper

type ErrorMapper func(w http.ResponseWriter, err error) bool

ErrorMapper is function that could customize serialization of error instance. All registered mappers all enumerated in order they were registered when instance of error is to be sent. First mapper that returns true will terminate enumeration and process will end.

type Interface

type Interface interface {
	// SendWithStatus sends object back to client with given status code.
	// If object to be send is error, then registered ErrorMappers can influence output instead.
	SendWithStatus(w http.ResponseWriter, v interface{}, status int)
	// SendBytes sends raw bytes to output, assuming content-type of current encoder
	SendBytes(w http.ResponseWriter, data []byte)
}

func DefaultOutput

func DefaultOutput() Interface

type PayloadEncoder

type PayloadEncoder func(w io.Writer, objToWrite interface{}) error

PayloadEncoder is responsible to serialize object to io.Writer

Jump to

Keyboard shortcuts

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