validation

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidEmail             = errors.New("provided email is invalid")
	ErrInvalidUsername          = errors.New("provided username is invalid")
	ErrIsRequired               = errors.New("value is required")
	ErrValueTooShort            = errors.New("value is too short")
	ErrValueTooLong             = errors.New("value is too long")
	ErrPasswordDontMatchConfirm = errors.New("the two passwords must match")
)
View Source
var RequiredRule required
View Source
var ValidEmailRule validEmail

Functions

func MaxLengthRule

func MaxLengthRule(length int) maxLength

func MinLengthRule

func MinLengthRule(length int) minLength

func PasswordMatchConfirmRule

func PasswordMatchConfirmRule(confirm string) passwordMatchConfirm

func ValidateStruct

func ValidateStruct(structToValidate any, validationMap map[string][]Rule) error

Types

type Error

type Error struct {
	Value               string
	FieldName           string
	Violations          []error
	ViolationsForHumans []string
}

func (Error) Error

func (e Error) Error() string

func (Error) GetFieldName

func (e Error) GetFieldName() string

func (Error) GetFieldValue

func (e Error) GetFieldValue() string

func (Error) GetHumanExplanations

func (e Error) GetHumanExplanations() []string

func (Error) GetViolations

func (e Error) GetViolations() []error

type Rule

type Rule interface {
	IsViolated(val any) bool
	Violation() error
	// TODO: should maybe be named HumanExplanation/HumanDescription/Description?
	ViolationForHumans(val string) string
}

type ValidationError

type ValidationError interface {
	Error() string
	GetFieldName() string
	GetFieldValue() string
	GetViolations() []error
	// TODO: rename this
	GetHumanExplanations() []string
}

type ValidationErrors

type ValidationErrors []ValidationError

func (ValidationErrors) Error

func (ve ValidationErrors) Error() string

func (ValidationErrors) Unwrap

func (ve ValidationErrors) Unwrap() []error

Unwrap() is used to make testing easier for now

Jump to

Keyboard shortcuts

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