validate

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrValidationFailed = errors.New("validation failed")

Functions

func ConfirmPassword

func ConfirmPassword(password string) func(string) error

ConfirmPassword returns a validator that ensures the two passwords match.

func CurrentPassword

func CurrentPassword(hash string) func(string) error

CurrentPassword returns a validator that ensures the value is valid when verified against the password hash.

func Fields

func Fields[T any]() map[string]Field

Fields returns the initial data needed by the template to render the fields: the field names.

func Register

func Register(name string, err string, f func(string) bool)

Register registers a custom validation function.

func RegisterWithParam

func RegisterWithParam(name string, err string, f func(value string, param string) bool)

RegisterWithParam registers a custom validation function that takes a parameter.

func Struct

func Struct[T any](s T, validatorMaps ...ValidatorMap) (map[string]Field, error)

Struct validates a struct's contents according to the rules set in the "validate" tag, and returns all the data needed by the template to render the form: the original submitted values, validation error messages, and the field names.

Types

type Field

type Field struct {
	Error string
	Value string
	Name  string
}

Field represents a submitted HTML field. Error is the error (if any) and Value is the original value that was submitted in the request.

type ValidatorMap

type ValidatorMap map[string]func(string) error

Jump to

Keyboard shortcuts

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