decoders

package
v0.0.6-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDecoderNotFound is returned when a reuqest doesn't have
	// enough information to determine a decoder
	ErrDecoderNotFound = errors.New("decoder could not be found")
	// JSONDecoder decodes data from a http.Request
	JSONDecoder = func(r io.Reader) Decoder {
		return json.NewDecoder(r)
	}
	// XMLDecoder decodes data from a http.Request
	XMLDecoder = func(r io.Reader) Decoder {
		return xml.NewDecoder(r)
	}
	// FormDecoder decodes data from a http.Request
	FormDecoder = func(r io.Reader) Decoder {
		return &formDecoder{r: r}
	}
)

Functions

func Register

func Register(s mime.Type, d newDecoder)

Register registers a new decoder to be used with jenny endpoints, it is to be recalled based on the mime-type

Types

type Decoder

type Decoder interface {
	Decode(v interface{}) error
}

Decoder is an interface that decodes http.Request.Body from their Content-Type mime types.

func RequestDecoder

func RequestDecoder(r *http.Request, accepts []mime.Type) (Decoder, error)

RequestDecoder returns a decoder for a given http.Request

func ResponseDecoder

func ResponseDecoder(r *http.Response) (Decoder, error)

ResponseDecoder returns a decoder for a given http.Request

Jump to

Keyboard shortcuts

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