encoding

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoEncoderAvailable = errors.New("codec not available")

ErrNoEncoderAvailable communicates that a codec is not available.

Functions

This section is empty.

Types

type Codec

type Codec struct {
	NewEncoder func(w io.Writer) Encoder
	NewDecoder func(r io.Reader) Decoder
	MimeTypes  []string
}

Codec combines an encoder, a decoder and a list of mime types.

type Codecs added in v0.1.4

type Codecs struct {
	Codecs           map[string]Codec
	OrderedMimeTypes []string
}

Codecs is a registry of codecs usually related to a route option.

func (*Codecs) Register added in v0.1.4

func (c *Codecs) Register(codec Codec)

Register registers a new codec to the codec registry.

type Decoder

type Decoder interface {
	// Decode decodes encoded value from the input stream into v.
	Decode(v interface{}) error
}

Decoder decodes encoded value from a input stream.

func ContentTypeDecoder

func ContentTypeDecoder(r io.Reader, contentTypeHeader string, codecs Codecs) (Decoder, error)

ContentTypeDecoder decodes the encoded data from r based on the Content-Type header value and the codecs that are available. If no codec is found, it returns a ErrNoEncoderAvailable.

type EditMode

type EditMode bool

EditMode allows to select an editable version of a codec. eg. HTML Forms for HTML codec

const (
	// EditOff indicates that the data is requested as read-only data.
	EditOff EditMode = false

	// EditOn indicates that the data is requested as editable data.
	EditOn EditMode = true
)

type Encoder

type Encoder interface {
	// Encode writes the codec data of v to the output stream.
	Encode(v interface{}) error
}

Encoder writes encoded value to an output stream.

func AcceptEncoder

func AcceptEncoder(w http.ResponseWriter, acceptHeader string, edit EditMode, codecs Codecs) Encoder

AcceptEncoder creates an new encoder for w based on the acceptHeader, the edit mode and the codecs that are available.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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