httpvalidator

package module
v0.0.0-...-96201f6 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Module used for validating user input in HTTP request and redirecting on error.

Index

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

func (v *Validator) ContainsRune(r rune) bool

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) Error

func (v *Validator) Error() error

Return Validator's Error

func (*Validator) LenInRange

func (v *Validator) LenInRange(start, end int)

Checks if the value's length is within the specified range.

func (*Validator) Match

func (v *Validator) Match(name, value string)

Compares value against another value. First argument is name, to be used in case of error. Not safe against timing attack.

func (*Validator) NoRune

func (v *Validator) NoRune(r rune)

Reports an error when the value contains a specified rune.

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.

func (*Validator) Trim

func (v *Validator) Trim()

Removes leading and trailing whitespace from the value if it exists

func (*Validator) Value

func (v *Validator) Value() string

Return Validator's Value

type ValidatorsLang

type ValidatorsLang struct {
	LenInRange              string
	PasswordUnsupportedChar string
	PasswordNotEnoughChars  string
	Match                   string
	NoRune                  string
	Email                   string
}

Struct used for translation.

Jump to

Keyboard shortcuts

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