Documentation ¶
Overview ¶
Package forms assists working with web forms and Request.Form
Index ¶
- Constants
- Variables
- func FormValue[T core.String](req *http.Request, field string) (value T, found bool, err error)
- func FormValueBool[T core.Bool](req *http.Request, field string) (value T, found bool, err error)
- func FormValueFloat[T core.Float](req *http.Request, field string) (value T, found bool, err error)
- func FormValueFloatInRange[T core.Float](req *http.Request, field string, minV, maxV T) (value T, found bool, err error)
- func FormValueFn[T any, S core.String](req *http.Request, field string, fn func(S) (T, error)) (T, bool, error)
- func FormValueSigned[T core.Signed](req *http.Request, field string, base int) (value T, found bool, err error)
- func FormValueSignedInRange[T core.Signed](req *http.Request, field string, base int, minV, maxV T) (value T, found bool, err error)
- func FormValueUnsigned[T core.Unsigned](req *http.Request, field string, base int) (value T, found bool, err error)
- func FormValueUnsignedInRange[T core.Unsigned](req *http.Request, field string, base int, minV, maxV T) (value T, found bool, err error)
- func FormValues[T core.String](req *http.Request, field string) (values []T, found bool, err error)
- func FormValuesBool[T core.Bool](req *http.Request, field string) (values []T, found bool, err error)
- func FormValuesFloat[T core.Float](req *http.Request, field string) (values []T, found bool, err error)
- func FormValuesFn[T any, S core.String](req *http.Request, field string, fn func(S) (T, error)) ([]T, bool, error)
- func FormValuesSigned[T core.Signed](req *http.Request, field string, base int) (values []T, found bool, err error)
- func FormValuesUnsigned[T core.Unsigned](req *http.Request, field string, base int) (values []T, found bool, err error)
- func FormatFloat[T core.Float](v T, fmt byte, prec int) string
- func FormatSigned[T core.Signed](v T, base int) string
- func FormatUnsigned[T core.Unsigned](v T, base int) string
- func IsEmptyString(err error) bool
- func IsNilOrEmptyString(err error) bool
- func ParseBool[T core.Bool](s string) (T, error)
- func ParseFloat[T core.Float](s string) (v T, err error)
- func ParseFloatInRange[T core.Float](s string, minV, maxV T) (value T, err error)
- func ParseForm(req *http.Request, maxMemory int64) (err error)
- func ParseSigned[T core.Signed](s string, base int) (v T, err error)
- func ParseSignedInRange[T core.Signed](s string, base int, minV, maxV T) (value T, err error)
- func ParseUnsigned[T core.Unsigned](s string, base int) (v T, err error)
- func ParseUnsignedInRange[T core.Unsigned](s string, base int, minV, maxV T) (value T, err error)
- func PostFormValue[T core.String](req *http.Request, field string) (value T, found bool, err error)
- func PostFormValueBool[T core.Bool](req *http.Request, field string) (value T, found bool, err error)
- func PostFormValueFloat[T core.Float](req *http.Request, field string) (value T, found bool, err error)
- func PostFormValueFloatInRange[T core.Float](req *http.Request, field string, minV, maxV T) (value T, found bool, err error)
- func PostFormValueFn[T any, S core.String](req *http.Request, field string, fn func(S) (T, error)) (T, bool, error)
- func PostFormValueSigned[T core.Signed](req *http.Request, field string, base int) (value T, found bool, err error)
- func PostFormValueSignedInRange[T core.Signed](req *http.Request, field string, base int, minV, maxV T) (value T, found bool, err error)
- func PostFormValueUnsigned[T core.Unsigned](req *http.Request, field string, base int) (value T, found bool, err error)
- func PostFormValueUnsignedInRange[T core.Unsigned](req *http.Request, field string, base int, minV, maxV T) (value T, found bool, err error)
- func PostFormValues[T core.String](req *http.Request, field string) (values []T, found bool, err error)
- func PostFormValuesBool[T core.Bool](req *http.Request, field string) (values []T, found bool, err error)
- func PostFormValuesFloat[T core.Float](req *http.Request, field string) (values []T, found bool, err error)
- func PostFormValuesFn[T any, S core.String](req *http.Request, field string, fn func(S) (T, error)) ([]T, bool, error)
- func PostFormValuesSigned[T core.Signed](req *http.Request, field string, base int) (values []T, found bool, err error)
- func PostFormValuesUnsigned[T core.Unsigned](req *http.Request, field string, base int) (values []T, found bool, err error)
- func ReadAll(body io.Reader, maxBytes int64) ([]byte, error)
- func UnmarshalFormJSON(b []byte) (url.Values, error)
- type NumError
Constants ¶
const DefaultFormMaxMemory = 1 << 20 // 1MiB
DefaultFormMaxMemory indicates the memory limit when parsing a form used when ParseForm is called without a positive number.
Variables ¶
var ErrMissing = errors.New("not specified")
ErrMissing indicates the field was missing from the request.
var ErrRange = strconv.ErrRange
ErrRange indicates the value of the field is out of range
var ErrSyntax = strconv.ErrSyntax
ErrSyntax indicates the field isn't of the correct form.
Functions ¶
func FormValue ¶ added in v0.6.5
FormValue reads a field from req.Form, after populating it if needed, and returning the trimmed string, an indicator saying if it was actually present, or an error if ParseForm failed.
func FormValueBool ¶ added in v0.6.5
FormValueBool reads a field from [http.Request#Form], after populating it if needed, and returns a core.Bool value, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func FormValueFloat ¶ added in v0.6.5
FormValueFloat reads a field from [http.Request#Form], after populating it if needed, and returns a core.Float value, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func FormValueFloatInRange ¶ added in v0.6.5
func FormValueFloatInRange[T core.Float](req *http.Request, field string, minV, maxV T) (value T, found bool, err error)
FormValueFloatInRange reads a field from [http.Request#Form], after populating it if needed, and returns a core.Float value, an indicator saying if it was actually, and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type or if it's outside the specified boundaries.
func FormValueFn ¶ added in v0.7.0
func FormValueFn[T any, S core.String](req *http.Request, field string, fn func(S) (T, error)) (T, bool, error)
FormValueFn reads a field from req.Form, and processes it through a helper function to get the value. FormValueFn also indicates if the field is missing, or if ParseForm or the conversion failed.
func FormValueSigned ¶ added in v0.6.5
func FormValueSigned[T core.Signed](req *http.Request, field string, base int) (value T, found bool, err error)
FormValueSigned reads a field from [http.Request#Form], after populating it if needed, and returns a core.Signed value, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func FormValueSignedInRange ¶ added in v0.6.5
func FormValueSignedInRange[T core.Signed](req *http.Request, field string, base int, minV, maxV T) (value T, found bool, err error)
FormValueSignedInRange reads a field from [http.Request#Form], after populating it if needed, and returns a core.Signed value, an indicator saying if it was actually, and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type or if it's outside the specified boundaries.
func FormValueUnsigned ¶ added in v0.6.5
func FormValueUnsigned[T core.Unsigned](req *http.Request, field string, base int) (value T, found bool, err error)
FormValueUnsigned reads a field from [http.Request#Form], after populating it if needed, and returns a core.Unsigned value, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func FormValueUnsignedInRange ¶ added in v0.6.5
func FormValueUnsignedInRange[T core.Unsigned](req *http.Request, field string, base int, minV, maxV T) (value T, found bool, err error)
FormValueUnsignedInRange reads a field from [http.Request#Form], after populating it if needed, and returns a core.Unsigned value, an indicator saying if it was actually, and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type or if it's outside the specified boundaries.
func FormValues ¶ added in v0.6.5
FormValues reads a field from req.Form, after populating it if needed, and returning the trimmed strings, an indicator saying if it was actually present, or an error if ParseForm failed. Empty values will be omitted.
func FormValuesBool ¶ added in v0.6.5
func FormValuesBool[T core.Bool](req *http.Request, field string) (values []T, found bool, err error)
FormValuesBool reads a field from [http.Request#Form], after populating it if needed, and returns its core.Bool values, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func FormValuesFloat ¶ added in v0.6.5
func FormValuesFloat[T core.Float](req *http.Request, field string) (values []T, found bool, err error)
FormValuesFloat reads a field from [http.Request#Form], after populating it if needed, and returns its core.Float values, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func FormValuesFn ¶ added in v0.7.0
func FormValuesFn[T any, S core.String](req *http.Request, field string, fn func(S) (T, error)) ([]T, bool, error)
FormValuesFn reads a field from req.Form, and processes all values through a helper function to get the values. FormValuesFn also indicates if the field is missing, or if ParseForm or the conversion failed.
func FormValuesSigned ¶ added in v0.6.5
func FormValuesSigned[T core.Signed](req *http.Request, field string, base int) (values []T, found bool, err error)
FormValuesSigned reads a field from [http.Request#Form], after populating it if needed, and returns its core.Signed values, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func FormValuesUnsigned ¶ added in v0.6.5
func FormValuesUnsigned[T core.Unsigned](req *http.Request, field string, base int) (values []T, found bool, err error)
FormValuesUnsigned reads a field from [http.Request#Form], after populating it if needed, and returns its core.Unsigned values, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func FormatFloat ¶ added in v0.6.5
FormatFloat extends strconv.FormatFloat working with any [Float] type.
func FormatSigned ¶ added in v0.6.5
FormatSigned extends strconv.FormatInt working with any [Signed] type.
func FormatUnsigned ¶ added in v0.6.5
FormatUnsigned extends strconv.FormatUint working with any [Unsigned] type.
func IsEmptyString ¶ added in v0.7.1
IsEmptyString recursively checks if the given error was caused by the argument being an empty string.
func IsNilOrEmptyString ¶ added in v0.7.1
IsNilOrEmptyString recursively checks if the given error was caused by the argument being an empty string, but it also succeeds when no error is given. To be used when testing an error condition.
func ParseBool ¶ added in v0.6.5
ParseBool extends the standard strconv.ParseBool making the comparison case-insensitive and allowing y/yes/n/no options.
func ParseFloat ¶ added in v0.6.5
ParseFloat converts a string to a floating point value of the correct size for the type using strconv.ParseFloat.
func ParseFloatInRange ¶ added in v0.6.5
ParseFloatInRange parses a string and and returns a core.Float value or a strconv.NumError if invalid or it's outside the specified boundaries.
func ParseForm ¶
ParseForm is similar to the standard request.ParseForm() but it handles urlencoded, multipart and JSON. For nested JSON objects ParseForm uses dots to join keys.
func ParseSigned ¶ added in v0.6.5
ParseSigned converts a string to a signed integer value of the correct size for the type using strconv.ParseInt.
func ParseSignedInRange ¶ added in v0.6.5
ParseSignedInRange parses a string and and returns a core.Signed value or a strconv.NumError if invalid or it's outside the specified boundaries.
func ParseUnsigned ¶ added in v0.6.5
ParseUnsigned converts a string to an unsigned integer value of the correct size for the type using strconv.ParseUint.
func ParseUnsignedInRange ¶ added in v0.6.5
ParseUnsignedInRange parses a string and and returns a core.Unsigned value or a strconv.NumError if invalid or it's outside the specified boundaries.
func PostFormValue ¶ added in v0.6.5
PostFormValue reads a field from req.PostForm, after populating it if needed, and returning the trimmed string, an indicator saying if it was actually present, or an error if ParseForm failed.
func PostFormValueBool ¶ added in v0.6.5
func PostFormValueBool[T core.Bool](req *http.Request, field string) (value T, found bool, err error)
PostFormValueBool reads a field from [http.Request#PostForm], after populating it if needed, and returns a core.Bool value, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func PostFormValueFloat ¶ added in v0.6.5
func PostFormValueFloat[T core.Float](req *http.Request, field string) (value T, found bool, err error)
PostFormValueFloat reads a field from [http.Request#PostForm], after populating it if needed, and returns a core.Float value, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func PostFormValueFloatInRange ¶ added in v0.6.5
func PostFormValueFloatInRange[T core.Float](req *http.Request, field string, minV, maxV T) (value T, found bool, err error)
PostFormValueFloatInRange reads a field from [http.Request#PostForm], after populating it if needed, and returns a core.Float value, an indicator saying if it was actually, and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type or if it's outside the specified boundaries.
func PostFormValueFn ¶ added in v0.7.0
func PostFormValueFn[T any, S core.String](req *http.Request, field string, fn func(S) (T, error)) (T, bool, error)
PostFormValueFn reads a field from req.PostForm, and processes it through a helper function to get the value. PostFormValueFn also indicates if the field is missing, or if ParseForm or the conversion failed.
func PostFormValueSigned ¶ added in v0.6.5
func PostFormValueSigned[T core.Signed](req *http.Request, field string, base int) (value T, found bool, err error)
PostFormValueSigned reads a field from [http.Request#PostForm], after populating it if needed, and returns a core.Signed value, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func PostFormValueSignedInRange ¶ added in v0.6.5
func PostFormValueSignedInRange[T core.Signed](req *http.Request, field string, base int, minV, maxV T) (value T, found bool, err error)
PostFormValueSignedInRange reads a field from [http.Request#PostForm], after populating it if needed, and returns a core.Signed value, an indicator saying if it was actually, and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type or if it's outside the specified boundaries.
func PostFormValueUnsigned ¶ added in v0.6.5
func PostFormValueUnsigned[T core.Unsigned](req *http.Request, field string, base int) (value T, found bool, err error)
PostFormValueUnsigned reads a field from [http.Request#PostForm], after populating it if needed, and returns a core.Unsigned value, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func PostFormValueUnsignedInRange ¶ added in v0.6.5
func PostFormValueUnsignedInRange[T core.Unsigned](req *http.Request, field string, base int, minV, maxV T) (value T, found bool, err error)
PostFormValueUnsignedInRange reads a field from [http.Request#PostForm], after populating it if needed, and returns a core.Unsigned value, an indicator saying if it was actually, and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type or if it's outside the specified boundaries.
func PostFormValues ¶ added in v0.6.5
func PostFormValues[T core.String](req *http.Request, field string) (values []T, found bool, err error)
PostFormValues reads a field from req.PostForm, after populating it if needed, and returning the trimmed strings, an indicator saying if it was actually present, or an error if ParseForm failed. Empty values will be omitted.
func PostFormValuesBool ¶ added in v0.6.5
func PostFormValuesBool[T core.Bool](req *http.Request, field string) (values []T, found bool, err error)
PostFormValuesBool reads a field from [http.Request#PostForm], after populating it if needed, and returns its core.Bool values, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func PostFormValuesFloat ¶ added in v0.6.5
func PostFormValuesFloat[T core.Float](req *http.Request, field string) (values []T, found bool, err error)
PostFormValuesFloat reads a field from [http.Request#PostForm], after populating it if needed, and returns its core.Float values, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func PostFormValuesFn ¶ added in v0.7.0
func PostFormValuesFn[T any, S core.String](req *http.Request, field string, fn func(S) (T, error)) ([]T, bool, error)
PostFormValuesFn reads a field from req.PostForm, and processes all values through a helper function to get the values. PostFormValuesFn also indicates if the field is missing, or if ParseForm or the conversion failed.
func PostFormValuesSigned ¶ added in v0.6.5
func PostFormValuesSigned[T core.Signed](req *http.Request, field string, base int) (values []T, found bool, err error)
PostFormValuesSigned reads a field from [http.Request#PostForm], after populating it if needed, and returns its core.Signed values, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.
func PostFormValuesUnsigned ¶ added in v0.6.5
func PostFormValuesUnsigned[T core.Unsigned](req *http.Request, field string, base int) (values []T, found bool, err error)
PostFormValuesUnsigned reads a field from [http.Request#PostForm], after populating it if needed, and returns its core.Unsigned values, an indicator saying if it was actually present and possibly an error. Errors could indicate ParseForm failed, or a strconv.NumError if it couldn't be converted to the intended type.