Documentation ¶
Index ¶
- Constants
- func NewConditionalCheck(clauses []ConditionClause) func(i interface{}, context interface{}) bool
- func NewEquals[T comparable](item T) func(i interface{}, context interface{}) bool
- func NewIsIn[T comparable](items []T) func(i interface{}, context interface{}) bool
- func NewIsNotIn[T comparable](items []T) func(i interface{}, context interface{}) bool
- func NewIsTypeOf(exemplar any) func(i interface{}, context interface{}) bool
- func NewNotEquals[T comparable](item T) func(i interface{}, context interface{}) bool
- type ConditionClause
- type Getter
Constants ¶
const ( ExhaustiveIn existenceCheckType = iota // All items are found in the comparison slice ExhaustiveNotIn // None of the items are in the comparison slice )
Variables ¶
This section is empty.
Functions ¶
func NewConditionalCheck ¶
func NewConditionalCheck(clauses []ConditionClause) func(i interface{}, context interface{}) bool
NewConditionalCheck creates a custom type validator which applies an arbitray number of ConditionClause checks, each with an arbitrary number of validators. The context object must support the Getter interface to apply the ConditionClause validations ... if it doesn't then the custom type validator returns false.
The validators within the ConditionClause slices must have been pre-registered to govalidator CustomTypeTagMap; if not found the custom type validator will panic.
func NewEquals ¶
func NewEquals[T comparable](item T) func(i interface{}, context interface{}) bool
NewEquals returns a function instance that will test equality of an interface against the specified item. The returned function can be used as a named func in the govalidators.CustomTypeTagMap for use in struct attribute value validations
func NewIsIn ¶
func NewIsIn[T comparable](items []T) func(i interface{}, context interface{}) bool
NewIsIn returns a function instance that will test existence of an interface against the specified items. The function will return true if the interface is a value and is present, or when the interface is a slice and all the values in the slice are present in items. The returned function can be used as a named func in the govalidators.CustomTypeTagMap for use in struct attribute value validations
func NewIsNotIn ¶
func NewIsNotIn[T comparable](items []T) func(i interface{}, context interface{}) bool
NewIsNotIn returns a function instance that will test non-existence of an interface against the specified items. The function will return true if the interface is a value and is not present, or when the interface is a slice and none of the values in the slice are present in items. The returned function can be used as a named func in the govalidators.CustomTypeTagMap for use in struct attribute value validations
func NewIsTypeOf ¶
NewIsTypeOf returns a function that returns true only if the interface type, determined by reflect.TypeOf(), is the same as the supplied exemplar. nil values always return false. The returned function can be used as a named func in the govalidators.CustomTypeTagMap for use in struct attribute value validations
func NewNotEquals ¶
func NewNotEquals[T comparable](item T) func(i interface{}, context interface{}) bool
NewNotEquals returns a function instance that will test non-equality of an interface against the specified item. The returned function can be used as a named func in the govalidators.CustomTypeTagMap for use in struct attribute value validations
Types ¶
type ConditionClause ¶
type ConditionClause struct { ContextAttrName string // The name of the attribute in the context, whose value to retrieve ValueConditions map[string][]string // The set of validations to apply based on the attribute's value }
ConditionClause defines which custom validators should be executed, based on the value of the specified attribute within the current context.