decoderx

package
v0.0.103 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: Apache-2.0 Imports: 15 Imported by: 25

Documentation

Index

Constants

View Source
const (
	// ParseErrorIgnore will ignore any parse errors caused by strconv.Parse* and use the
	// raw form field value, which is a string, when such a parse error occurs.
	ParseErrorIgnore parseErrorStrategy = iota + 1

	// ParseErrorDefault will ignore any parse errors caused by strconv.Parse* and use the
	// default value of the type to be casted, e.g. float64(0), string("").
	ParseErrorDefault

	// ParseErrorReturn will abort and return with an error if strconv.Parse* returns
	// an error.
	ParseErrorReturn
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTP

type HTTP struct{}

HTTP decodes json and form-data from HTTP Request Bodies.

func NewHTTP

func NewHTTP() *HTTP

NewHTTP creates a new HTTP decoder.

func (*HTTP) Decode

func (t *HTTP) Decode(r *http.Request, destination interface{}, opts ...HTTPDecoderOption) error

Decode takes a HTTP Request Body and decodes it into destination.

type HTTPDecoderOption

type HTTPDecoderOption func(*httpDecoderOptions)

HTTPDecoderOption configures the HTTP decoder.

func HTTPDecoderSetIgnoreParseErrorsStrategy added in v0.0.83

func HTTPDecoderSetIgnoreParseErrorsStrategy(strategy parseErrorStrategy) HTTPDecoderOption

HTTPDecoderSetIgnoreParseErrorsStrategy sets a strategy for dealing with strconv.Parse* errors:

- decoderx.ParseErrorIgnore will ignore any parse errors caused by strconv.Parse* and use the raw form field value, which is a string, when such a parse error occurs. (default) - decoderx.ParseErrorDefault will ignore any parse errors caused by strconv.Parse* and use the default value of the type to be casted, e.g. float64(0), string(""). - decoderx.ParseErrorReturn will abort and return with an error if strconv.Parse* returns an error.

func HTTPDecoderSetMaxCircularReferenceDepth added in v0.0.83

func HTTPDecoderSetMaxCircularReferenceDepth(depth uint8) HTTPDecoderOption

HTTPDecoderSetMaxCircularReferenceDepth sets the maximum recursive reference resolution depth.

func HTTPDecoderSetValidatePayloads added in v0.0.82

func HTTPDecoderSetValidatePayloads(validate bool) HTTPDecoderOption

HTTPDecoderSetValidatePayloads sets if payloads should be validated or not.

func HTTPFormDecoder

func HTTPFormDecoder() HTTPDecoderOption

HTTPFormDecoder configures the HTTP decoder to only accept form-data (application/x-www-form-urlencoded, multipart/form-data)

func HTTPJSONDecoder

func HTTPJSONDecoder() HTTPDecoderOption

HTTPJSONDecoder configures the HTTP decoder to only accept form-data (application/json).

func HTTPJSONSchemaCompiler added in v0.0.82

func HTTPJSONSchemaCompiler(ref string, compiler *jsonschema.Compiler) HTTPDecoderOption

HTTPJSONSchemaCompiler sets a JSON schema to be used for validation and type assertion of incoming requests.

func HTTPRawJSONSchemaCompiler added in v0.0.82

func HTTPRawJSONSchemaCompiler(raw []byte) (HTTPDecoderOption, error)

HTTPRawJSONSchemaCompiler uses a JSON Schema Compiler with the provided JSON Schema in raw byte form.

func MustHTTPRawJSONSchemaCompiler added in v0.0.82

func MustHTTPRawJSONSchemaCompiler(raw []byte) HTTPDecoderOption

MustHTTPRawJSONSchemaCompiler uses HTTPRawJSONSchemaCompiler and panics on error.

Jump to

Keyboard shortcuts

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