field

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagName = "form"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolParser added in v0.2.0

type BoolParser struct{}

func (BoolParser) ParseForm added in v0.3.0

func (BoolParser) ParseForm(field string) (any, error)

type CannotParseErr added in v0.2.0

type CannotParseErr struct {
	Kind reflect.Kind
}

func (CannotParseErr) Error added in v0.2.0

func (i CannotParseErr) Error() string

type Complex64Parser added in v0.2.0

type Complex64Parser struct{}

func (Complex64Parser) ParseForm added in v0.3.0

func (Complex64Parser) ParseForm(field string) (any, error)

type Complex128Parser added in v0.2.0

type Complex128Parser struct{}

func (Complex128Parser) ParseForm added in v0.3.0

func (Complex128Parser) ParseForm(field string) (any, error)

type Field

type Field struct {
	// Name is the name of the field inside the struct
	Name string
	// Parser used to turn string value into Field type
	Parser Parser
	// MetaData contains additional Tag metadata used during decoding
	MetaData Tag
	// contains filtered or unexported fields
}

Field contains the metadata and type parser to decode a key-value pair from url.Values into a struct field.

func New

func New(f reflect.StructField) (Field, error)

func (*Field) Decode

func (f *Field) Decode(values url.Values, target reflect.Value) error

Decode retrieves value from url.Values, converts its value into the target type and then sets the value on target

type Float32Parser added in v0.2.0

type Float32Parser struct{}

func (Float32Parser) ParseForm added in v0.3.0

func (Float32Parser) ParseForm(field string) (any, error)

type Float64Parser added in v0.2.0

type Float64Parser struct{}

func (Float64Parser) ParseForm added in v0.3.0

func (Float64Parser) ParseForm(field string) (any, error)

type Int8Parser added in v0.2.0

type Int8Parser struct{}

func (Int8Parser) ParseForm added in v0.3.0

func (Int8Parser) ParseForm(field string) (any, error)

type Int16Parser added in v0.2.0

type Int16Parser struct{}

func (Int16Parser) ParseForm added in v0.3.0

func (Int16Parser) ParseForm(field string) (any, error)

type Int32Parser added in v0.2.0

type Int32Parser struct{}

func (Int32Parser) ParseForm added in v0.3.0

func (Int32Parser) ParseForm(field string) (any, error)

type Int64Parser added in v0.2.0

type Int64Parser struct{}

func (Int64Parser) ParseForm added in v0.3.0

func (Int64Parser) ParseForm(field string) (any, error)

type IntParser added in v0.2.0

type IntParser struct{}

IntParser parses the field string as a 64 bit int and casts it to int

func (IntParser) ParseForm added in v0.3.0

func (IntParser) ParseForm(field string) (any, error)

type Parser added in v0.2.0

type Parser interface {
	// ParseForm converts a string into a type.
	ParseForm(field string) (any, error)
}

Parser converts a string into a type. Which type is controlled by the implementation of the Parser. Parser must always return the same type.

type RequiredFieldMissingErr

type RequiredFieldMissingErr struct {
	Field string
}

func (RequiredFieldMissingErr) Error

func (r RequiredFieldMissingErr) Error() string

type StringParser added in v0.2.0

type StringParser struct{}

StringParser returns the field string unchanged

func (StringParser) ParseForm added in v0.3.0

func (StringParser) ParseForm(field string) (any, error)

type Tag

type Tag struct {
	// If Alias is not an empty string, it will be used instead of the struct field name.
	Alias string
	// If Required is true decode will fail if FieldName is not present in url.Values.
	Required bool
	// If Regex is not nil it will be used to validate the field value before decoding it.
	Regex *regexp.Regexp
}

Tag represents the configuration options that can be with the struct tag (see TagName) set on struct fields.

func ParseTag

func ParseTag(tag string) Tag

ParseTag parses the string of the struct tag into a Tag struct

func (Tag) FieldName

func (t Tag) FieldName(fieldName string) string

FieldName returns the key for the url.Values lookup.

type Uint8Parser added in v0.2.0

type Uint8Parser struct{}

func (Uint8Parser) ParseForm added in v0.3.0

func (Uint8Parser) ParseForm(field string) (any, error)

type Uint16Parser added in v0.2.0

type Uint16Parser struct{}

func (Uint16Parser) ParseForm added in v0.3.0

func (Uint16Parser) ParseForm(field string) (any, error)

type Uint32Parser added in v0.2.0

type Uint32Parser struct{}

func (Uint32Parser) ParseForm added in v0.3.0

func (Uint32Parser) ParseForm(field string) (any, error)

type Uint64Parser added in v0.2.0

type Uint64Parser struct{}

func (Uint64Parser) ParseForm added in v0.3.0

func (Uint64Parser) ParseForm(field string) (any, error)

type UintParser added in v0.2.0

type UintParser struct{}

UintParser parses the field string as a 64 bit uint and casts it to uint

func (UintParser) ParseForm added in v0.3.0

func (UintParser) ParseForm(field string) (any, error)

Jump to

Keyboard shortcuts

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