Documentation ¶
Overview ¶
Package forms implements utilities to parse and validate data.
Index ¶
- type CheckFunc
- func BoolRequired() CheckFunc
- func DecBtw(n, m string) CheckFunc
- func DecGt(n string) CheckFunc
- func DecGte(n string) CheckFunc
- func DecLt(n string) CheckFunc
- func DecLte(n string) CheckFunc
- func DecRequired() CheckFunc
- func DtAfter(n string) CheckFunc
- func DtBefore(n string) CheckFunc
- func DtInFuture() CheckFunc
- func DtInPast() CheckFunc
- func DtRequired() CheckFunc
- func FltBtw(n, m float64) CheckFunc
- func FltGt(n float64) CheckFunc
- func FltGte(n float64) CheckFunc
- func FltIn(choices []float64) CheckFunc
- func FltLt(n float64) CheckFunc
- func FltLte(n float64) CheckFunc
- func FltRequired() CheckFunc
- func IntBtw(n, m int) CheckFunc
- func IntGt(n int) CheckFunc
- func IntGte(n int) CheckFunc
- func IntIn(choices []int) CheckFunc
- func IntLt(n int) CheckFunc
- func IntLte(n int) CheckFunc
- func IntRequired() CheckFunc
- func StrBtw(n, m int) CheckFunc
- func StrEmail() CheckFunc
- func StrGt(n int) CheckFunc
- func StrGte(n int) CheckFunc
- func StrIn(choices []string) CheckFunc
- func StrLt(n int) CheckFunc
- func StrLte(n int) CheckFunc
- func StrMatches(rx *regexp.Regexp, errMsg string) CheckFunc
- func StrRequired() CheckFunc
- func StrUrl() CheckFunc
- type Field
- type Form
- func (f *Form) CleanBool(name, value string, funcs ...CheckFunc)
- func (f *Form) CleanDate(name, value string, funcs ...CheckFunc)
- func (f *Form) CleanDecimal(name, value string, funcs ...CheckFunc)
- func (f *Form) CleanExtra(cond bool, err error)
- func (f *Form) CleanFloat(name, value string, funcs ...CheckFunc)
- func (f *Form) CleanInteger(name, value string, funcs ...CheckFunc)
- func (f *Form) CleanString(name, value string, funcs ...CheckFunc)
- func (f *Form) CleanedBool(name string) bool
- func (f *Form) CleanedDate(name string) time.Time
- func (f *Form) CleanedDecimal(name string) big.Rat
- func (f *Form) CleanedFloat(name string) float64
- func (f *Form) CleanedInteger(name string) int
- func (f *Form) CleanedString(name string) string
- func (f *Form) ExtraErrors() []error
- func (f *Form) Field(name string) (Field, bool)
- func (f *Form) HasError(target any) bool
- func (f *Form) IsValid() bool
- func (f *Form) MustField(name string) Field
- func (f *Form) Names() []string
- type ParseError
- type ParseFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckFunc ¶
CheckFunc is a function which validates a Field.
func StrMatches ¶
Checks that a string matches the given regex.
type Field ¶
type Field struct { String string Integer int Float float64 Bool bool Decimal big.Rat Date time.Time // contains filtered or unexported fields }
Field represents a parsed value.
func (Field) Err ¶ added in v0.0.8
Err returns the error associated with the field's parsing or validation.
type Form ¶
type Form struct {
// contains filtered or unexported fields
}
Form is a type which parses and validates form data.
Values can be parsed into a desired type, like an int, date, bool, etc. Validation functions can also be provided, which ensures that the parsed type is properly vetted before being retrieved.
func (*Form) CleanDecimal ¶
CleanDecimal cleans the given value as a decimal.
func (*Form) CleanExtra ¶ added in v0.0.6
CleanExtra adds the error to the extra errors list if the condition is true.
func (*Form) CleanFloat ¶
CleanFloat cleans the given value as a float.
func (*Form) CleanInteger ¶
CleanInteger cleans the given value as a integer.
func (*Form) CleanString ¶
CleanString cleans the given value as a string.
func (*Form) CleanedBool ¶
CleanedBool retrieves the named field as a bool.
func (*Form) CleanedDate ¶
CleanedDate retrieves the named field as a date.
func (*Form) CleanedDecimal ¶
CleanedDecimal retrieves the named field as a decimal.
func (*Form) CleanedFloat ¶
CleanedFloat retrieves the named field as a float.
func (*Form) CleanedInteger ¶
CleanedInteger retrieves the named field as an integer.
func (*Form) CleanedString ¶
CleanedString retrieves the named field as a string.
func (*Form) ExtraErrors ¶ added in v0.0.6
ExtraErrors returns the extra errors slice.
type ParseError ¶
type ParseError struct {
Msg string
}
ParseError represents when a value fails to parse into a specific type.
func (ParseError) Error ¶
func (p ParseError) Error() string
func (ParseError) String ¶
func (p ParseError) String() string