Documentation ¶
Overview ¶
Description: This package contains functions that are used to validate nil values.
Description: This package provides a set of validators that can be used to validate struct fields. It also provides a registry to store and run these validators.
Index ¶
- func CheckNilValues(params ...interface{}) error
- type Validator
- func NewE164PhoneValidator() Validator
- func NewNonNilPointerFieldElemIsUTCDateValidator() Validator
- func NewNonNilPointerValidator() Validator
- func NewNonPointerFieldFloat32InsideRangeValidator(min float32, max float32) Validator
- func NewNonPointerFieldFloat64InsideRangeValidator(min float64, max float64) Validator
- func NewNonPointerFieldIntInsideRangeValidator(min int, max int) Validator
- func NewNonPointerFieldUintInsideRangeValidator(min uint, max uint) Validator
- func NewNonZeroPointerElemValidator() Validator
- func NewNonZeroValidator() Validator
- func NewPointerFieldE164PhoneValidator() Validator
- func NewPointerFieldFloat32InsideRangeValidator(min float32, max float32) Validator
- func NewPointerFieldFloat64InsideRangeValidator(min float64, max float64) Validator
- func NewPointerFieldInt32InsideRangeValidator(min int32, max int32) Validator
- func NewPointerFieldInt64InsideRangeValidator(min int64, max int64) Validator
- func NewPointerFieldIntInsideRangeValidator(min int, max int) Validator
- func NewPointerFieldIsValidBPC47Validator() Validator
- func NewPointerFieldIsValidISOCurrency() Validator
- func NewPointerFieldUintInsideRangeValidator(min uint, max uint) Validator
- type ValidatorRegistryInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckNilValues ¶
func CheckNilValues(params ...interface{}) error
CheckNilValues checks if any of the passed parameters are nil.
NOTE: Only parameters that have the possibility of being nil should be passed to this function. Passing a non-nil value of a type that cannot be nil (e.g., a string) will cause a panic.
Types ¶
type Validator ¶ added in v1.15.12
Validator is a function type that performs validation on a string value.
The function returns an error if the validation fails.
func NewE164PhoneValidator ¶
func NewE164PhoneValidator() Validator
NewE164Validator returns a validator that checks if a field is a string and is a valid E.164 phone number.
func NewNonNilPointerFieldElemIsUTCDateValidator ¶
func NewNonNilPointerFieldElemIsUTCDateValidator() Validator
NewNonNilPointerFieldElemIsUTCDateValidator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is a valid UTC date.
func NewNonNilPointerValidator ¶
func NewNonNilPointerValidator() Validator
NewNonNilPointerValidator returns a validator that checks if a field is a pointer and is not nil.
func NewNonPointerFieldFloat32InsideRangeValidator ¶ added in v1.19.6
NewNonPointerFieldFloat32InsideRangeValidator returns a validator that checks if a field is a float32 and is inside a given range.
func NewNonPointerFieldFloat64InsideRangeValidator ¶ added in v1.19.6
NewNonPointerFieldFloat64InsideRangeValidator returns a validator that checks if a field is a float64 and is inside a given range.
func NewNonPointerFieldIntInsideRangeValidator ¶ added in v1.13.4
NewNonPointerFieldIntInsideRangeValidator returns a validator that checks if a field is an int and is inside a given range.
func NewNonPointerFieldUintInsideRangeValidator ¶ added in v1.17.20
NewNonPointerFieldUintInsideRangeValidator returns a validator that checks if a field is an uint and is inside a given range.
func NewNonZeroPointerElemValidator ¶
func NewNonZeroPointerElemValidator() Validator
NewNonNilPointerElemValidator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is not zero.
func NewNonZeroValidator ¶
func NewNonZeroValidator() Validator
NewNonZeroValidator returns a validator that checks if a field is not a pointer and is not zero.
func NewPointerFieldE164PhoneValidator ¶ added in v1.20.0
func NewPointerFieldE164PhoneValidator() Validator
NewPointerFieldE164Validator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is a valid E.164 phone number.
func NewPointerFieldFloat32InsideRangeValidator ¶ added in v1.19.6
NewPointerFieldFloat32InsideRangeValidator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is a float32 inside a given range.
func NewPointerFieldFloat64InsideRangeValidator ¶ added in v1.19.6
NewPointerFieldFloat64InsideRangeValidator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is a float64 inside a given range.
func NewPointerFieldInt32InsideRangeValidator ¶ added in v1.22.0
NewPointerFieldInt32InsideRangeValidator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is an int inside a given range.
func NewPointerFieldInt64InsideRangeValidator ¶ added in v1.22.0
NewPointerFieldInt64InsideRangeValidator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is an int inside a given range.
func NewPointerFieldIntInsideRangeValidator ¶ added in v1.13.4
NewPointerFieldIntInsideRangeValidator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is an int inside a given range.
func NewPointerFieldIsValidBPC47Validator ¶ added in v1.14.6
func NewPointerFieldIsValidBPC47Validator() Validator
NewPointerFieldIsValidBPC47Validator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is a valid BCP47 language tag.
func NewPointerFieldIsValidISOCurrency ¶ added in v1.23.0
func NewPointerFieldIsValidISOCurrency() Validator
NewPointerFieldIsValidISOCurrency returns a validator that checks if a field is a pointer, is not nil, and its underlying value is a valid ISO currency code.
func NewPointerFieldUintInsideRangeValidator ¶ added in v1.17.20
NewPointerFieldUintInsideRangeValidator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is an uint inside a given range.
type ValidatorRegistryInterface ¶
type ValidatorRegistryInterface interface { AddValidator(string, Validator) RunTags(interface{}, string) error }
ValidatorRegistryInterface is an interface that defines the methods that a validatorRegistry must implement.
func NewValidatorRegistry ¶
func NewValidatorRegistry() ValidatorRegistryInterface
NewValidatorRegistry creates a new validatorRegistry and initializes its validators map.
It returns a ValidatorRegistryInterface.