Documentation
¶
Overview ¶
Package forms provides a way to safely and conveniently extract html Form data using a definied schema.
Index ¶
- Variables
- func MustParse(r *http.Request, schema Schema)
- func Parse(r *http.Request, schema Schema) error
- func ParseValues(data url.Values, schema Schema) error
- type IntType
- type Parser
- func Bool(b *bool) Parser
- func BoolOr(b *bool, alt bool) Parser
- func Float(f *float64) Parser
- func FloatOr(f *float64, alt float64) Parser
- func Int[T IntType](i *T) Parser
- func IntOr[T IntType](i *T, alt T) Parser
- func Secret(s **conceal.Text) Parser
- func String[T StringType](s *T) Parser
- func StringOr[T StringType](s *T, alt T) Parser
- func Strings[T StringType](s *[]T) Parser
- func StringsOr[T StringType](s *[]T, alt []T) Parser
- type Schema
- type StringType
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func MustParse ¶ added in v1.1.0
Parse uses the given Schema to parse the HTTP form values in the given HTTP Request. If the values of the form do not match the schema, or required values are missing, a panic is triggered.
Types ¶
type IntType ¶
type IntType interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}
IntType represents any type compatible with the Go integer built-in types, to be used as a destination for writing the value of a form value.
type Parser ¶
A Parser implementation is capable of extracting a value from the value of an url.Values, which is a slice of string.
func Bool ¶
Bool is used to extract a form data value into a Go bool. If the value is not a bool or is missing than an error is returned during parsing.
func BoolOr ¶
BoolOr is used to extract a form data value into a Go bool. If the value is missing, then the alt value is used instead.
func Float ¶
Float is used to extract a form data value into a Go float64. If the value is not a float or is missing then an error is returned during parsing.
func FloatOr ¶
FloatOr is used to extract a form data value into a Go float64. If the value is missing, then the alt value is used instead.
func Int ¶
Int is used to extract a form data value into a Go int. If the value is not an int or is missing then an error is returned during parsing.
func IntOr ¶
IntOr is used to extract a form data value into a Go int. If the value is missing, then the alt value is used instead.
func Secret ¶
Secret is used to extract a form data value into a Go conceal.Text. If the value is missing then an error is returned during parsing.
func String ¶
func String[T StringType](s *T) Parser
String is used to extract a form data value into a Go string. If the value is not a string or is missing then an error is returned during parsing.
func StringOr ¶
func StringOr[T StringType](s *T, alt T) Parser
StringOr is used to extract a form data value into a Go string. If the value is missing, then the alt value is used instead.
func Strings ¶ added in v1.0.3
func Strings[T StringType](s *[]T) Parser
Strings is used to extract a form data value into a slice of Go strings.
If the form value is missing, then an error is returned during parsing.
func StringsOr ¶ added in v1.0.4
func StringsOr[T StringType](s *[]T, alt []T) Parser
StringsOr is used to extract multiple form values for a given key into a slice of Go strings.
If the form value is missing, then the given alt value is used instead.
type Schema ¶
A Schema describes how a set of url.Values should be parsed. Typically these are coming from an http.Request.Form from inside an http.Handler responding to an inbound request.
type StringType ¶
type StringType interface {
~string
}
StringType represents any type compatible with the Go string built-in type, to be used as a destination for writing the value of an environment variable.