Documentation ¶
Overview ¶
Package validationjuice provides utility functions for validating struct fields based on their tags.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewNonNilValidator ¶
NewNonNilValidator creates a new validator that checks if a field is non-nil. The validator is associated with a tag value, and can be used to validate struct fields with that tag value.
func NewNonZeroValidator ¶
NewNonZeroValidator creates a new validator that checks if a field is non-zero. The validator is associated with a tag value, and can be used to validate struct fields with that tag value.
Types ¶
type ValidatorRegistry ¶
ValidatorRegistry is a struct that holds a map of validators. Each validator is associated with a tag, and can be used to validate struct fields with that tag.
func (*ValidatorRegistry) AddValidator ¶
func (r *ValidatorRegistry) AddValidator(tag string, validator funccup.Validator)
AddValidator adds a new validator to the ValidatorRegistry. The validator is associated with a tag, and can be used to validate struct fields with that tag.
func (*ValidatorRegistry) CheckTags ¶
func (r *ValidatorRegistry) CheckTags(data interface{}, tagKey string) error
CheckTags checks the tags of the fields in a struct. If a field has a tag that matches a validator in the ValidatorRegistry, it will run that validator on the field. It returns an error if the data is not a struct or a pointer to a struct, or if a validator returns an error.
type ValidatorRegistryInterface ¶
type ValidatorRegistryInterface interface { AddValidator(string, funccup.Validator) CheckTags(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.