validator

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPasswordIsRequired = errors.New("password is required")
	ErrPasswordIsCommon   = errors.New("password is common")
)
View Source
var CommonPasswords = []string{}/* 10000 elements not displayed */

CommonPasswords list is from https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10k-most-common.txt

View Source
var RgxEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")

Functions

func AllIn

func AllIn[T comparable](values []T, safelist ...T) bool

func Between

func Between[T constraints.Ordered](value, min, max T) bool

func In

func In[T comparable](value T, safelist ...T) bool

func IsCommonPassword added in v0.3.1

func IsCommonPassword(value string) bool

func IsEmail

func IsEmail[T ~string](value T) bool

func IsURL

func IsURL(value string) bool

func Matches

func Matches(value string, rx *regexp.Regexp) bool

func MaxRunes

func MaxRunes(value string, n int) bool

func MinRunes

func MinRunes(value string, n int) bool

func NoDuplicates

func NoDuplicates[T comparable](values []T) bool

func NotBlank

func NotBlank(value string) bool

func NotIn

func NotIn[T comparable](value T, blocklist ...T) bool

func Validate

func Validate[T any](data T, validators ...ValidatorFunc[T]) error

Types

type Validator

type Validator struct {
	Errors []error
	// contains filtered or unexported fields
}

func FromError added in v0.3.1

func FromError(err error) (v *Validator)

func (*Validator) AddError added in v0.3.1

func (v *Validator) AddError(err ...error)

func (*Validator) Check added in v0.3.1

func (v *Validator) Check(ok bool, err error)

func (*Validator) Err added in v0.3.1

func (v *Validator) Err(msg string) error

func (*Validator) HasErrors added in v0.3.1

func (v *Validator) HasErrors() bool

type ValidatorFunc added in v0.3.1

type ValidatorFunc[T any] func(T) error

Jump to

Keyboard shortcuts

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