Documentation
¶
Overview ¶
Package validate provides an easy way to validate the data contained in structs, typically being DTOs containing user input.
Index ¶
- func Check[T any](v *Validator, key string, value T, validatorFunc ValidatorFunc[T])
- func CheckOptional[T any](v *Validator, key string, value *T, validatorFunc ValidatorFunc[T])
- func IsNotEmpty(value string) (bool, string)
- func IsValidTimeZone(value string) (bool, string)
- type ValidatedType
- type Validator
- type ValidatorFunc
- func IsGreaterThan[T shared.IntType](value1 T) ValidatorFunc[T]
- func IsGreaterThanOrEqual[T shared.IntType](value1 T) ValidatorFunc[T]
- func IsInSlice[T comparable](slice []T) ValidatorFunc[T]
- func IsLesserThan[T shared.IntType](value1 T) ValidatorFunc[T]
- func IsLesserThanOrEqual[T shared.IntType](value1 T) ValidatorFunc[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
func Check[T any](v *Validator, key string, value T, validatorFunc ValidatorFunc[T])
Check checks if value passes the validatorFunc. The provided key is used for creating the errors map of the Validator.
func CheckOptional ¶ added in v0.1.9
func CheckOptional[T any]( v *Validator, key string, value *T, validatorFunc ValidatorFunc[T], )
CheckOptional checks if value passes the validatorFunc, when the value is provided. The provided key is used for creating the errors map of the Validator.
func IsNotEmpty ¶
IsNotEmpty checks that the provided value is not empty.
func IsValidTimeZone ¶
IsValidTimeZone checks if the provided value is a valid IANA timezone.
Types ¶
type ValidatedType ¶ added in v0.1.1
ValidatedType is implemented by any struct with a Validate method.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator is used to validate contents of structs using Check.
type ValidatorFunc ¶
ValidatorFunc is the expected format used for validating data using Check.
func IsGreaterThan ¶ added in v0.1.9
func IsGreaterThan[T shared.IntType](value1 T) ValidatorFunc[T]
IsGreaterThan checks if the provided value2 > value1.
func IsGreaterThanOrEqual ¶ added in v0.1.9
func IsGreaterThanOrEqual[T shared.IntType](value1 T) ValidatorFunc[T]
IsGreaterThanOrEqual checks if the provided value2 >= value1.
func IsInSlice ¶ added in v0.1.9
func IsInSlice[T comparable](slice []T) ValidatorFunc[T]
IsInSlice checks if the provided value is part of the provided slice.
func IsLesserThan ¶ added in v0.1.9
func IsLesserThan[T shared.IntType](value1 T) ValidatorFunc[T]
IsLesserThan checks if the provided value2 < value1.
func IsLesserThanOrEqual ¶ added in v0.1.9
func IsLesserThanOrEqual[T shared.IntType](value1 T) ValidatorFunc[T]
IsLesserThanOrEqual checks if the provided value2 <= value1.