Documentation ¶
Overview ¶
Package validate provides a generic implementation for any object type using validation rules
Index ¶
- Variables
- func ConfigByField[T any](configReader io.Reader, fieldname string) (T, error)
- func DenyFunc[S ~[]E, E any](target S, check func(E) error) error
- func NewFailedRuleError(rule string, id string) error
- type Validator
- func (v Validator[ObjectT, ConfigT]) ReadConfigAndValidate(objects []ObjectT, configReader io.Reader, field string) error
- func (v Validator[ObjectT, ConfigT]) Validate(objects []ObjectT, config ConfigT) error
- func (v Validator[ObjectT, ConfigT]) WithAllowRules(rules ...func(ObjectT, ConfigT) bool) Validator[ObjectT, ConfigT]
- func (v Validator[ObjectT, ConfigT]) WithValidationRules(rules ...func([]ObjectT, ConfigT) error) Validator[ObjectT, ConfigT]
Constants ¶
This section is empty.
Variables ¶
var ErrConfig = errors.New("cannot validate, invalid configuration")
ErrConfig return this error if the configuration file is invalid
var ErrFailedRule = errors.New("Failed Rule")
ErrFailedRule return this error if an object fails a validation rule
Functions ¶
func ConfigByField ¶
ConfigByField get the config field name after decoding
func DenyFunc ¶ added in v0.2.0
DenyFunc generic execution of a check function over a slice of objects
func NewFailedRuleError ¶
NewFailedRuleError convenience function for error wrapping
Types ¶
type Validator ¶
Validator generic validation runner
func NewValidator ¶
NewValidator used to create specific implementations of a validator
func (Validator[ObjectT, ConfigT]) ReadConfigAndValidate ¶
func (v Validator[ObjectT, ConfigT]) ReadConfigAndValidate(objects []ObjectT, configReader io.Reader, field string) error
ReadConfigAndValidate validate after decoding the configuration object
func (Validator[ObjectT, ConfigT]) WithAllowRules ¶
func (v Validator[ObjectT, ConfigT]) WithAllowRules(rules ...func(ObjectT, ConfigT) bool) Validator[ObjectT, ConfigT]
WithAllowRules define the allow rules which will skip validation
func (Validator[ObjectT, ConfigT]) WithValidationRules ¶
func (v Validator[ObjectT, ConfigT]) WithValidationRules(rules ...func([]ObjectT, ConfigT) error) Validator[ObjectT, ConfigT]
WithValidationRules define the fail validation rules, all must pass