Documentation
¶
Overview ¶
Module used for validating user input in HTTP request and redirecting on error.
Index ¶
- func PostFormMiddleware(size int64, redirect func(http.ResponseWriter, *http.Request), ...) http.Handler
- type Validator
- func (v *Validator) ContainsRune(r rune) bool
- func (v *Validator) Email()
- func (v *Validator) Error() error
- func (v *Validator) LenInRange(start, end int)
- func (v *Validator) Match(name, value string)
- func (v *Validator) NoRune(r rune)
- func (v *Validator) PasswordChars()
- func (v *Validator) RedirectError(w http.ResponseWriter, r *http.Request, ...)
- func (v *Validator) Trim()
- func (v *Validator) Value() string
- type ValidatorsLang
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PostFormMiddleware ¶
func PostFormMiddleware(size int64, redirect func(http.ResponseWriter, *http.Request), next http.Handler) http.Handler
Middleware for limiting the size of the POST request body. Size is specified in bytes. If size is exceeded or another error is encountered, it executes httpflashes.RedirectError and returns.
Types ¶
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Struct used for basic validation.
func New ¶
func New(name, value string, lang *ValidatorsLang) *Validator
Creates new Validator struct. Takes field name (used for displaying meaningful errors), the value to validate and reference to ValidatorsLang.
func (*Validator) ContainsRune ¶
Returns true if the value contains a specified rune, otherwise false
func (*Validator) Email ¶
func (v *Validator) Email()
Checks whether the value is a valid email address
func (*Validator) LenInRange ¶
Checks if the value's length is within the specified range.
func (*Validator) Match ¶
Compares value against another value. First argument is name, to be used in case of error. Not safe against timing attack.
func (*Validator) PasswordChars ¶
func (v *Validator) PasswordChars()
Checks whether the value contains all required characters to form a password. The rules are: - contains at least one capital letter; - contains at least one lowercase letter; - contains at least one digit; - contains at least one special character; - does not contain any whitespace or non-ASCII characters; - minimum number of characters is 8.
func (*Validator) RedirectError ¶
func (v *Validator) RedirectError(w http.ResponseWriter, r *http.Request, redirect func(http.ResponseWriter, *http.Request))
Wrapper around httpflashes.RedirectError for Validator errors.