Documentation
¶
Index ¶
- func Contains[T ~string](input T, values ...T) bool
- func Empty[T ~string](input T) bool
- func EndsWith[T ~string](input T, suffixes ...T) bool
- func In[T comparable](input T, list ...T) bool
- func IsNumber[T ~string](input T) bool
- func Len[S any, T ~[]S](input T, l int) bool
- func LenRange[S any, T ~[]S](input T, low, high int) bool
- func LengthMax[T ~string](input T, max int) bool
- func LengthMin[T ~string](input T, min int) bool
- func LengthRange[T ~string](input T, min, max int) bool
- func Matches(input string, re *regexp.Regexp) bool
- func Max[T cmp.Ordered](input T, max T) bool
- func Min[T cmp.Ordered](input T, min T) bool
- func Not(predicate bool) bool
- func Range[T cmp.Ordered](input T, min, max T) bool
- func StartsWith[T ~string](input T, prefixes ...T) bool
- func Unique[T cmp.Ordered](values []T) bool
- type Case
- type ValidationError
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func In ¶
func In[T comparable](input T, list ...T) bool
In checks if the input is present in the given list of arguments.
func Len ¶ added in v0.4.0
Len checks if the given input is of given length. For strings, use [Length*] functions.
func LenRange ¶ added in v0.4.0
LenRange checks if the given input is in the given range, inclusive. For strings, use [Length*] functions.
func LengthMax ¶ added in v0.4.0
LengthMax checks if a string's utf8 length is equal or lesser the given maximum.
func LengthMin ¶ added in v0.4.0
LengthMin checks if a string's utf8 length is equal or greater the given minimum.
func LengthRange ¶ added in v0.4.0
LengthRange checks if a string's utf8 length is inside the given range, inclusive.
func Max ¶
Max checks if the input is equal or lesser than a maximum. For length, use LengthMax instead.
func Min ¶
Min checks if the input is equal or bigger than a minimum. For length, use LengthMin instead.
func Range ¶
Range checks if the input is inside a number range, inclusive. For length, use LengthRange instead.
func StartsWith ¶
StartsWith check whether the input starts with one of the given prefixes.
Types ¶
type Case ¶
Case is a test-case, consisting of two parts. Cond will call a function that returns a boolean. If it returns false, Msg will be added to the [Validator.Errors].
type ValidationError ¶ added in v0.2.0
ValidationError holds all validation error messages. It also implements the error interface.
func (ValidationError) Error ¶ added in v0.2.0
func (v ValidationError) Error() string
Error returns validation errors in the following format:
"field_1: validation error, field_2: first error"
type Validator ¶
type Validator struct {
Errors ValidationError `json:"errors"`
}
Validator will check for cases by [Check] method and will return a boolean with the [Validate] method. If a validation error happens, the Msg will be stored inside the [Errors] map.