decoder

package
v0.0.0-...-83625b3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Decoders = map[string]func(body io.Reader, v interface{}) error{
	"application/json": JSONDecoder,
	"application/yaml": YAMLDecoder,
	"application/toml": TOMLDecoder,
	"application/xml":  XMLDecoder,
	"text/xml":         XMLDecoder,
	"text/csv":         CSVDecoder,
}

Decoders are POST data decoders. The key is the content type, the value is a decoder that decodes the contents of the Reader into v.

View Source
var NoDecoderErr = errors.New("no decoder found for the request content type")

Functions

func CSVDecoder

func CSVDecoder(body io.Reader, v interface{}) error

CSVDecoder decodes the request body using the built-in CSV reader into v.

v must be *[][]string

func Decode

func Decode(r *http.Request, v interface{}) error

Decode decodes a request body into v. After decoding, it closes the body.

This function considers only the Content-Type header, and requires its presence. See the Decoders variable for more information.

func JSONDecoder

func JSONDecoder(body io.Reader, v interface{}) error

JSONDecoder decodes the request body using the built-in JSON decoder into v.

func MustDecode

func MustDecode(r *http.Request, v interface{})

MustDecode is the same as Decode(), but it panics instead of returning an error.

When using the kit with the recommended settings, this method is recommended instead of Decode(), because the panic will get caught by the error handler middleware.

func TOMLDecoder

func TOMLDecoder(body io.Reader, v interface{}) error

TOMLDecoder decodes the request body using a TOML decoder into v.

func XMLDecoder

func XMLDecoder(body io.Reader, v interface{}) error

XMLDecoder decodes the request body using the built-in XML decoder into v.

func YAMLDecoder

func YAMLDecoder(body io.Reader, v interface{}) error

YAMLDecoder decodes the request body using a YAML decoder into v.

Types

This section is empty.

Jump to

Keyboard shortcuts

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