frm

package
v2.0.0-...-10e4721 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package frm decodes HTTP form and query parameters.

Index

Constants

View Source
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.

Variables

This section is empty.

Functions

func Decode

func Decode(vs url.Values, dst any) error

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

Types

type DecodeCustomTypeFunc

type DecodeCustomTypeFunc func([]string) (any, 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 any) 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 []any, fields []any) *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.

Jump to

Keyboard shortcuts

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