validator

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FileRX = regexp.MustCompile(`^[^/]*$`)
View Source
var HeaderRX = regexp.MustCompile("^([a-zA-Z0-9!#$%&'*+.^_`" + `|~-]+):[\S]+(, [a-zA-Z0-9!#$%&'*+.^_` + "`|~-]+:[" + `\S]+)*$`)
View Source
var MethodRX = regexp.MustCompile("^(GET|POST|PUT|DELETE|PATCH)$")
View Source
var ProxyRX = regexp.MustCompile("^(http://|socks5://)")
View Source
var URLRX = regexp.MustCompile("((((https?|ftps?|gopher|telnet|nntp)://)|(mailto:|news:))([-%()_.!~*';/?:@&=+$,A-Za-z0-9])+)")

Functions

func EqualValue

func EqualValue[T comparable](value1 T, value2 T) bool

EqualValue returns true if the values are equals

func Matches

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

Matches return true if match with the pattern

func MaxChars

func MaxChars(value string, n int) bool

MaxChars returns true if a value contains no more than n characters.

func MaxNumber

func MaxNumber[T number](value T, n T) bool

MaxNumber returns true if a value is minor that n

func MinChars

func MinChars(value string, n int) bool

MinChars returns true if a value contains more than n characters.

func MinNumber

func MinNumber[T number](value T, n T) bool

MinNumber returns true if a value is greater than n

func NotBlank

func NotBlank(value string) bool

NotBlank returns true if a value is not an empty string.

func NotCero

func NotCero[T number](value T) bool

NotCero return true if a value is not 0

func PermittedValue

func PermittedValue[T comparable](value T, permittedValues ...T) bool

PermittedValue returns true if a value is in a list of permitted.

func Unique

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

Unique return true if all values in a slice are unique.

Types

type OptionError

type OptionError struct {
	Option string
	Err    string
}

type Validator

type Validator struct {
	Errors []*OptionError
}

func (*Validator) AddError

func (v *Validator) AddError(key, message string)

AddFieldError adds an error message to the OptionError slice

func (*Validator) Check

func (v *Validator) Check(ok bool, key, message string)

CheckField adds an error message to the OptionError slice only if a validation Check is not 'ok'.

func (*Validator) Valid

func (v *Validator) Valid() bool

Valid returns true if the validator struct doesn't contain any errors.

Jump to

Keyboard shortcuts

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