Documentation ¶
Index ¶
- Constants
- type HTTP
- type HTTPDecoderOption
- func HTTPDecoderAllowedMethods(method ...string) HTTPDecoderOption
- func HTTPDecoderJSONFollowsFormFormat() HTTPDecoderOption
- func HTTPDecoderSetIgnoreParseErrorsStrategy(strategy parseErrorStrategy) HTTPDecoderOption
- func HTTPDecoderSetMaxCircularReferenceDepth(depth uint8) HTTPDecoderOption
- func HTTPDecoderSetValidatePayloads(validate bool) HTTPDecoderOption
- func HTTPDecoderUseQueryAndBody() HTTPDecoderOption
- func HTTPFormDecoder() HTTPDecoderOption
- func HTTPJSONDecoder() HTTPDecoderOption
- func HTTPJSONSchemaCompiler(ref string, compiler *jsonschema.Compiler) HTTPDecoderOption
- func HTTPKeepRequestBody(keep bool) HTTPDecoderOption
- func HTTPRawJSONSchemaCompiler(raw []byte) (HTTPDecoderOption, error)
- func MustHTTPRawJSONSchemaCompiler(raw []byte) HTTPDecoderOption
Constants ¶
const ( // ParseErrorIgnoreConversionErrors will ignore any errors caused by strconv.Parse* and use the // raw form field value, which is a string, when such a parse error occurs. // // If the JSON Schema defines `{"ratio": {"type": "number"}}` but `ratio=foobar` then field // `ratio` will be handled as a string. If the destination struct is a `json.RawMessage`, then // the output will be `{"ratio": "foobar"}`. ParseErrorIgnoreConversionErrors parseErrorStrategy = iota + 1 // ParseErrorUseEmptyValueOnConversionErrors 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(""). // // If the JSON Schema defines `{"ratio": {"type": "number"}}` but `ratio=foobar` then field // `ratio` will receive the default value for the primitive type (here `0.0` for `number`). // If the destination struct is a `json.RawMessage`, then the output will be `{"ratio": 0.0}`. ParseErrorUseEmptyValueOnConversionErrors // ParseErrorReturnOnConversionErrors will abort and return with an error if strconv.Parse* returns // an error. // // If the JSON Schema defines `{"ratio": {"type": "number"}}` but `ratio=foobar` the parser aborts // and returns an error, here: `strconv.ParseFloat: parsing "foobar"`. ParseErrorReturnOnConversionErrors )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPDecoderOption ¶
type HTTPDecoderOption func(*httpDecoderOptions)
HTTPDecoderOption configures the HTTP decoder.
func HTTPDecoderAllowedMethods ¶ added in v0.0.147
func HTTPDecoderAllowedMethods(method ...string) HTTPDecoderOption
HTTPDecoderAllowedMethods sets the allowed HTTP methods. Defaults are POST, PUT, PATCH.
func HTTPDecoderJSONFollowsFormFormat ¶ added in v0.0.146
func HTTPDecoderJSONFollowsFormFormat() HTTPDecoderOption
HTTPDecoderJSONFollowsFormFormat if set tells the decoder that JSON follows the same conventions as the form decoder, meaning `{"foo.bar": "..."}` is translated to `{"foo": {"bar": "..."}}`.
func HTTPDecoderSetIgnoreParseErrorsStrategy ¶ added in v0.0.83
func HTTPDecoderSetIgnoreParseErrorsStrategy(strategy parseErrorStrategy) HTTPDecoderOption
HTTPDecoderSetIgnoreParseErrorsStrategy sets a strategy for dealing with strconv.Parse* errors:
- decoderx.ParseErrorIgnoreConversionErrors 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.ParseErrorUseEmptyValueOnConversionErrors 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.ParseErrorReturnOnConversionErrors 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 HTTPDecoderUseQueryAndBody ¶ added in v0.0.214
func HTTPDecoderUseQueryAndBody() HTTPDecoderOption
HTTPDecoderUseQueryAndBody will check both the HTTP body and the HTTP query params when decoding. Only relevant for non-GET operations.
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 HTTPKeepRequestBody ¶ added in v0.0.207
func HTTPKeepRequestBody(keep bool) HTTPDecoderOption
HTTPKeepRequestBody configures the HTTP decoder to allow other HTTP request body readers to read the body as well by keeping the data in memory.
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.