formam: Index | Files

package formam

import ""

Package formam decodes HTTP form and query parameters.


Package Files

errors.go formam.go


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.

func Decode Uses

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

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

type DecodeCustomTypeFunc Uses

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

DecodeCustomTypeFunc for decoding a custom type.

type Decoder Uses

type Decoder struct {
    // contains filtered or unexported fields

Decoder to decode a form.

func NewDecoder Uses

func NewDecoder(opts *DecoderOptions) *Decoder

NewDecoder creates a new instance of Decoder.

func (Decoder) Decode Uses

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 Uses

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

RegisterCustomType registers a functions for decoding custom types.

type DecoderOptions Uses

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 Uses

type Error struct {
    // contains filtered or unexported fields

Error indicates a error produced

func (*Error) Cause Uses

func (s *Error) Cause() error

Cause implements the causer interface from

func (Error) Code Uses

func (s Error) Code() uint8

Code for this error. See the ErrCode* constants.

func (*Error) Error Uses

func (s *Error) Error() string

func (Error) MarshalJSON Uses

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

MarshalJSON implements the interface Marshaler

func (Error) Path Uses

func (s Error) Path() string

Path for this error.

Package formam imports 9 packages (graph) and is imported by 67 packages. Updated 2020-09-27. Refresh now. Tools for package owners.