v3 – github.com/monoculum/formam/v3 Index | Files

package formam

import "github.com/monoculum/formam/v3"

Package formam decodes HTTP form and query parameters.

Index

Constants

const (
	ErrCodeNotAPointer  uint8 = iota // Didn't pass a pointer to Decode().
	ErrCodeArrayIndex                // Error attempting to use an array index (e.g. foo[2]).
	ErrCodeConversion                // Error converting field to the type.
	ErrCodeUnknownType               // Unknown type.
	ErrCodeUnknownField              // No struct field for passed parameter (will never be used if IgnoreUnknownKeys is set).
	ErrCodeRange                     // Number is out of range (e.g. parsing 300 in uint8 would overflow).
	ErrCodeArraySize                 // Array longer than MaxSize.
)

Error codes.

Functions

func Decode

func Decode(vs url.Values, dst interface{}) error

Decode the url.Values and populate the destination dst, which must be a pointer.

Types

type DecodeCustomTypeFunc

type DecodeCustomTypeFunc func([]string) (interface{}, error)

DecodeCustomTypeFunc for decoding a custom type.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder to decode a form.

func NewDecoder

func NewDecoder(opts *DecoderOptions) *Decoder

NewDecoder creates a new instance of Decoder.

func (Decoder) Decode

func (dec Decoder) Decode(vs url.Values, dst interface{}) error

Decode the url.Values and populate the destination dst, which must be a pointer.

func (*Decoder) RegisterCustomType

func (dec *Decoder) RegisterCustomType(fn DecodeCustomTypeFunc, types []interface{}, fields []interface{}) *Decoder

RegisterCustomType registers a functions for decoding custom types.

type DecoderOptions

type DecoderOptions struct {
	// Struct field tag name; default is "formam".
	TagName string

	// Prefer UnmarshalText over custom types.
	PrefUnmarshalText bool

	// Disable UnmarshalText interface
	DisableUnmarshalText bool

	// Ignore unknown form fields. By default unknown fields are an error
	// (although all valid keys will still be decoded).
	IgnoreUnknownKeys bool

	// The maximum array size that formam will create. This is limited to
	// prevent malicious input to create huge arrays to starve the server of
	// memory.
	//
	// The default is 16,000; set to -1 to disable.
	MaxSize int
}

DecoderOptions options for decoding the values.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error indicates a error produced

func (*Error) Cause

func (s *Error) Cause() error

Cause implements the causer interface from github.com/pkg/errors.

func (Error) Code

func (s Error) Code() uint8

Code for this error. See the ErrCode* constants.

func (*Error) Error

func (s *Error) Error() string

func (Error) MarshalJSON

func (s Error) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface Marshaler

func (Error) Path

func (s Error) Path() string

Path for this error.

Source Files

errors.go formam.go

Version
v3.6.0 (latest)
Published
Oct 2, 2021
Platform
js/wasm
Imports
9 packages
Last checked
now

Tools for package owners.