Documentation
¶
Index ¶
- Variables
- func BuildPredicateDict() dag.PredicateDict
- func KindToString(kind FieldKind) string
- type Bindings
- func (b *Bindings) Bind(object Reflectable) (*BoundObject, bool)
- func (b *Bindings) BindWithReflection(object any) (*BoundObject, bool)
- func (b *Bindings) Build(object Reflectable) (*StructDescriptor, bool)
- func (b *Bindings) BuildWithReflection(object any) (*StructDescriptor, bool)
- func (b *Bindings) Register(object *StructDescriptor) bool
- type BoundObject
- type FTEQBuilder
- type FTEQPredicate
- type FTINBuilder
- type FTINPredicate
- type FVEQBuilder
- type FVEQPredicate
- type FVFALSEBuilder
- type FVFALSEPredicate
- type FVGTBuilder
- type FVGTEBuilder
- type FVGTEPredicate
- type FVGTPredicate
- type FVINBuilder
- type FVINPredicate
- type FVLTBuilder
- type FVLTEBuilder
- type FVLTEPredicate
- type FVLTPredicate
- type FVNEQBuilder
- type FVNEQPredicate
- type FVNILBuilder
- type FVNILPredicate
- type FVREMBuilder
- type FVREMPredicate
- type FVTRUEBuilder
- type FVTRUEPredicate
- type FieldAccessorFn
- type FieldInfo
- type FieldKind
- type MetaPredicate
- func (meta *MetaPredicate) Debug(isn, token string) string
- func (meta *MetaPredicate) GetKeyAsFieldInfo(input dag.Filterable) (*FieldInfo, bool)
- func (meta *MetaPredicate) GetKeyAsFloat64(input dag.Filterable) (float64, bool)
- func (meta *MetaPredicate) GetKeyAsString(input dag.Filterable) (string, bool)
- func (meta *MetaPredicate) GetKeyAsValue(input dag.Filterable) (any, bool)
- func (meta *MetaPredicate) GetValueAsAny() (any, bool)
- func (meta *MetaPredicate) GetValueAsBool() (bool, bool)
- func (meta *MetaPredicate) GetValueAsComplex128() (complex128, bool)
- func (meta *MetaPredicate) GetValueAsFloat64() (float64, bool)
- func (meta *MetaPredicate) GetValueAsInt64() (int64, bool)
- func (meta *MetaPredicate) GetValueAsString() (string, bool)
- func (meta *MetaPredicate) GetValueAsUint64() (uint64, bool)
- func (meta *MetaPredicate) String(token string) string
- type Reflectable
- type StructDescriptor
- type Validator
- func (v *Validator) ClearFailures()
- func (v *Validator) Compile(specs []dag.RuleSpec) []error
- func (v *Validator) CompileAction(spec dag.ActionSpec) (dag.ActionFn, error)
- func (v *Validator) CompileFailure(spec dag.FailureSpec) (dag.ActionFn, error)
- func (v *Validator) Evaluate(input dag.Filterable)
- func (v *Validator) Export(writer io.Writer)
- func (v *Validator) Failures() []error
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidSlice = errors.Base("invalid slice") ErrNotCanonicalisable = errors.Base("value cannot be canonicalised") ErrNotComparable = errors.Base("value cannot be compared") )
var ( ErrInvalidRegexp = errors.Base("invalid regexp") ErrRegexpParse = errors.Base("error parsing regexp") )
var (
ErrFailInvoked = errors.Base("fail action was invoked")
)
var (
ErrValueNotString = errors.Base("value is not a string")
)
Functions ¶
func BuildPredicateDict ¶
func BuildPredicateDict() dag.PredicateDict
func KindToString ¶
Types ¶
type Bindings ¶
type Bindings struct {
Bindings map[reflect.Type]*StructDescriptor
// contains filtered or unexported fields
}
func NewBindings ¶
func NewBindings() *Bindings
func (*Bindings) Bind ¶
func (b *Bindings) Bind(object Reflectable) (*BoundObject, bool)
func (*Bindings) BindWithReflection ¶
func (b *Bindings) BindWithReflection(object any) (*BoundObject, bool)
func (*Bindings) Build ¶
func (b *Bindings) Build(object Reflectable) (*StructDescriptor, bool)
func (*Bindings) BuildWithReflection ¶
func (b *Bindings) BuildWithReflection(object any) (*StructDescriptor, bool)
func (*Bindings) Register ¶
func (b *Bindings) Register(object *StructDescriptor) bool
type BoundObject ¶
type BoundObject struct {
Descriptor *StructDescriptor
Binding any
}
func (*BoundObject) GetValue ¶
func (bo *BoundObject) GetValue(key string) (any, bool)
Get the value for the given key from the bound object.
This works by using the accessor obtained via reflection during the predicate building phase.
func (*BoundObject) Keys ¶
func (bo *BoundObject) Keys() []string
func (*BoundObject) String ¶
func (bo *BoundObject) String() string
type FTEQBuilder ¶
type FTEQBuilder struct{}
func (*FTEQBuilder) Token ¶
func (bld *FTEQBuilder) Token() string
type FTEQPredicate ¶
type FTEQPredicate struct {
MetaPredicate
}
Field Type Equality.
This predicate compares the type of the structure's field. If it is equal then the predicate returns true.
func (*FTEQPredicate) Debug ¶
func (pred *FTEQPredicate) Debug() string
func (*FTEQPredicate) Eval ¶
func (pred *FTEQPredicate) Eval(_ context.Context, input dag.Filterable) bool
func (*FTEQPredicate) Instruction ¶
func (pred *FTEQPredicate) Instruction() string
func (*FTEQPredicate) String ¶
func (pred *FTEQPredicate) String() string
func (*FTEQPredicate) Token ¶
func (pred *FTEQPredicate) Token() string
type FTINBuilder ¶
type FTINBuilder struct{}
func (*FTINBuilder) Token ¶
func (bld *FTINBuilder) Token() string
type FTINPredicate ¶
type FTINPredicate struct {
MetaPredicate
// contains filtered or unexported fields
}
Field Type In.
This predicate returns true of the type of a field in the input structure is one of the provided values in the predicate.
func (*FTINPredicate) Debug ¶
func (pred *FTINPredicate) Debug() string
func (*FTINPredicate) Eval ¶
func (pred *FTINPredicate) Eval(_ context.Context, input dag.Filterable) bool
func (*FTINPredicate) Instruction ¶
func (pred *FTINPredicate) Instruction() string
func (*FTINPredicate) String ¶
func (pred *FTINPredicate) String() string
func (*FTINPredicate) Token ¶
func (pred *FTINPredicate) Token() string
type FVEQBuilder ¶
type FVEQBuilder struct{}
func (*FVEQBuilder) Token ¶
func (bld *FVEQBuilder) Token() string
type FVEQPredicate ¶
type FVEQPredicate struct {
MetaPredicate
}
Field Value Equality.
This predicate compares the value to that in the structure. If they are equal then the predicate returns true.
The predicate will take various circumstances into consideration while checking the value:
If the field is `any` then the comparison will match just the type of the value rather than using the type of the field along with the value.
If the field is integer, then the structure's field must have a bit width large enough to hold the value.
func (*FVEQPredicate) Debug ¶
func (pred *FVEQPredicate) Debug() string
func (*FVEQPredicate) Eval ¶
func (pred *FVEQPredicate) Eval(_ context.Context, input dag.Filterable) bool
func (*FVEQPredicate) Instruction ¶
func (pred *FVEQPredicate) Instruction() string
func (*FVEQPredicate) String ¶
func (pred *FVEQPredicate) String() string
func (*FVEQPredicate) Token ¶
func (pred *FVEQPredicate) Token() string
type FVFALSEBuilder ¶
type FVFALSEBuilder struct{}
func (*FVFALSEBuilder) Token ¶
func (bld *FVFALSEBuilder) Token() string
type FVFALSEPredicate ¶
type FVFALSEPredicate struct {
MetaPredicate
}
Field Value is Logically False.
This predicate returns true if the value of the filtered field is logically false.
A logical false value is any value that is empty or zero. The following are examples of this:
"" string, 0 numeric, [] array
Logical falsehood is not the same as `nil`, so if you are looking for nil values then you should look at `FVNIL` instead.
Structures are a special case. They are never logically false. This is because the validator does not recurse into structures. If you wish to deal with structures within structures, then those sub-structures require validation by themselves. How you do that is up to you.
Interfaces are also a special case. An interface can be considered logically false if it is `nil`, but it can also be considered logically false if the wrapped value is zero or empty.
func (*FVFALSEPredicate) Debug ¶
func (pred *FVFALSEPredicate) Debug() string
func (*FVFALSEPredicate) Eval ¶
func (pred *FVFALSEPredicate) Eval(_ context.Context, input dag.Filterable) bool
func (*FVFALSEPredicate) Instruction ¶
func (pred *FVFALSEPredicate) Instruction() string
func (*FVFALSEPredicate) String ¶
func (pred *FVFALSEPredicate) String() string
func (*FVFALSEPredicate) Token ¶
func (pred *FVFALSEPredicate) Token() string
type FVGTBuilder ¶
type FVGTBuilder struct{}
func (*FVGTBuilder) Token ¶
func (bld *FVGTBuilder) Token() string
type FVGTEBuilder ¶
type FVGTEBuilder struct{}
func (*FVGTEBuilder) Token ¶
func (bld *FVGTEBuilder) Token() string
type FVGTEPredicate ¶
type FVGTEPredicate struct {
MetaPredicate
}
This predicate returns true if the value in the structure is greater than or equal to the value in the predicate.
func (*FVGTEPredicate) Debug ¶
func (pred *FVGTEPredicate) Debug() string
func (*FVGTEPredicate) Eval ¶
func (pred *FVGTEPredicate) Eval(_ context.Context, input dag.Filterable) bool
func (*FVGTEPredicate) Instruction ¶
func (pred *FVGTEPredicate) Instruction() string
func (*FVGTEPredicate) String ¶
func (pred *FVGTEPredicate) String() string
func (*FVGTEPredicate) Token ¶
func (pred *FVGTEPredicate) Token() string
type FVGTPredicate ¶
type FVGTPredicate struct {
MetaPredicate
}
This predicate returns true if the value in the structure is greater than the value in the predicate.
func (*FVGTPredicate) Debug ¶
func (pred *FVGTPredicate) Debug() string
func (*FVGTPredicate) Eval ¶
func (pred *FVGTPredicate) Eval(_ context.Context, input dag.Filterable) bool
func (*FVGTPredicate) Instruction ¶
func (pred *FVGTPredicate) Instruction() string
func (*FVGTPredicate) String ¶
func (pred *FVGTPredicate) String() string
func (*FVGTPredicate) Token ¶
func (pred *FVGTPredicate) Token() string
type FVINBuilder ¶
type FVINBuilder struct{}
func (*FVINBuilder) Token ¶
func (bld *FVINBuilder) Token() string
type FVINPredicate ¶
type FVINPredicate struct {
MetaPredicate
// contains filtered or unexported fields
}
Field Value In.
This predicate returns true if the value in the structure is one of the provided values in the predicate.
func (*FVINPredicate) Debug ¶
func (pred *FVINPredicate) Debug() string
func (*FVINPredicate) Eval ¶
func (pred *FVINPredicate) Eval(_ context.Context, input dag.Filterable) bool
func (*FVINPredicate) Instruction ¶
func (pred *FVINPredicate) Instruction() string
func (*FVINPredicate) String ¶
func (pred *FVINPredicate) String() string
func (*FVINPredicate) Token ¶
func (pred *FVINPredicate) Token() string
type FVLTBuilder ¶
type FVLTBuilder struct{}
func (*FVLTBuilder) Token ¶
func (bld *FVLTBuilder) Token() string
type FVLTEBuilder ¶
type FVLTEBuilder struct{}
func (*FVLTEBuilder) Token ¶
func (bld *FVLTEBuilder) Token() string
type FVLTEPredicate ¶
type FVLTEPredicate struct {
MetaPredicate
}
This predicate returns true if the value in the structure is lesser than or equal to the value in the predicate.
func (*FVLTEPredicate) Debug ¶
func (pred *FVLTEPredicate) Debug() string
func (*FVLTEPredicate) Eval ¶
func (pred *FVLTEPredicate) Eval(_ context.Context, input dag.Filterable) bool
func (*FVLTEPredicate) Instruction ¶
func (pred *FVLTEPredicate) Instruction() string
func (*FVLTEPredicate) String ¶
func (pred *FVLTEPredicate) String() string
func (*FVLTEPredicate) Token ¶
func (pred *FVLTEPredicate) Token() string
type FVLTPredicate ¶
type FVLTPredicate struct {
MetaPredicate
}
This predicate returns true if the value in the structure is lesser than the value in the predicate.
func (*FVLTPredicate) Debug ¶
func (pred *FVLTPredicate) Debug() string
func (*FVLTPredicate) Eval ¶
func (pred *FVLTPredicate) Eval(_ context.Context, input dag.Filterable) bool
func (*FVLTPredicate) Instruction ¶
func (pred *FVLTPredicate) Instruction() string
func (*FVLTPredicate) String ¶
func (pred *FVLTPredicate) String() string
func (*FVLTPredicate) Token ¶
func (pred *FVLTPredicate) Token() string
type FVNEQBuilder ¶
type FVNEQBuilder struct{}
func (*FVNEQBuilder) Token ¶
func (bld *FVNEQBuilder) Token() string
type FVNEQPredicate ¶
type FVNEQPredicate struct {
FVEQPredicate
}
Field Valie Inequality.
This predicate compares the value to that in the structure. If they are not equal then the predicate returns true.
The predicate will take various circumstances into consideration while checking the value:
If the field is `any` then the comparison will match just the type of the value rather than using the type of the field along with the value.
If the field is integer then the structure's field must have a bit width large enough to hold the value.
func (*FVNEQPredicate) Debug ¶
func (pred *FVNEQPredicate) Debug() string
func (*FVNEQPredicate) Eval ¶
func (pred *FVNEQPredicate) Eval(ctx context.Context, input dag.Filterable) bool
func (*FVNEQPredicate) Instruction ¶
func (pred *FVNEQPredicate) Instruction() string
func (*FVNEQPredicate) String ¶
func (pred *FVNEQPredicate) String() string
func (*FVNEQPredicate) Token ¶
func (pred *FVNEQPredicate) Token() string
type FVNILBuilder ¶
type FVNILBuilder struct{}
func (*FVNILBuilder) Token ¶
func (bld *FVNILBuilder) Token() string
type FVNILPredicate ¶
type FVNILPredicate struct {
MetaPredicate
}
Field Value Is Nil.
This predicate returns true if and only if the **reference** value of the filtered field is `nil`.
If the field value is a concrete type (e.g. string, int, float, bool etc), then the predicate will return false.
It only applies to types that can be `nil` in Go--e.g. pointers, slices, maps, interfaces, et al. If you're looking to test whether a field is "logically nil" (e.g. zero, false, empty) then consider using `FVFALSE` instead.
func (*FVNILPredicate) Debug ¶
func (pred *FVNILPredicate) Debug() string
func (*FVNILPredicate) Eval ¶
func (pred *FVNILPredicate) Eval(_ context.Context, input dag.Filterable) bool
func (*FVNILPredicate) Instruction ¶
func (pred *FVNILPredicate) Instruction() string
func (*FVNILPredicate) String ¶
func (pred *FVNILPredicate) String() string
func (*FVNILPredicate) Token ¶
func (pred *FVNILPredicate) Token() string
type FVREMBuilder ¶
type FVREMBuilder struct{}
func (*FVREMBuilder) Token ¶
func (bld *FVREMBuilder) Token() string
type FVREMPredicate ¶
type FVREMPredicate struct {
MetaPredicate
// contains filtered or unexported fields
}
func (*FVREMPredicate) Debug ¶
func (pred *FVREMPredicate) Debug() string
func (*FVREMPredicate) Eval ¶
func (pred *FVREMPredicate) Eval(_ context.Context, input dag.Filterable) bool
func (*FVREMPredicate) Instruction ¶
func (pred *FVREMPredicate) Instruction() string
func (*FVREMPredicate) String ¶
func (pred *FVREMPredicate) String() string
func (*FVREMPredicate) Token ¶
func (pred *FVREMPredicate) Token() string
type FVTRUEBuilder ¶
type FVTRUEBuilder struct{}
func (*FVTRUEBuilder) Token ¶
func (bld *FVTRUEBuilder) Token() string
type FVTRUEPredicate ¶
type FVTRUEPredicate struct {
FVFALSEPredicate
}
Field Value is Logically True.
This predicate returns true if the value of the filtered field is logically true.
A logical true value is any value that is not empty or zero.
For more details on how this works, see `FVFALSE`.
func (*FVTRUEPredicate) Debug ¶
func (pred *FVTRUEPredicate) Debug() string
func (*FVTRUEPredicate) Eval ¶
func (pred *FVTRUEPredicate) Eval(ctx context.Context, input dag.Filterable) bool
func (*FVTRUEPredicate) Instruction ¶
func (pred *FVTRUEPredicate) Instruction() string
func (*FVTRUEPredicate) String ¶
func (pred *FVTRUEPredicate) String() string
func (*FVTRUEPredicate) Token ¶
func (pred *FVTRUEPredicate) Token() string
type FieldAccessorFn ¶
type FieldInfo ¶
type MetaPredicate ¶
type MetaPredicate struct {
// contains filtered or unexported fields
}
func (*MetaPredicate) Debug ¶
func (meta *MetaPredicate) Debug(isn, token string) string
func (*MetaPredicate) GetKeyAsFieldInfo ¶
func (meta *MetaPredicate) GetKeyAsFieldInfo(input dag.Filterable) (*FieldInfo, bool)
Return the `Filterable`'s field information.
This is directed through to `BoundObject.Description.Fields`.
func (*MetaPredicate) GetKeyAsFloat64 ¶
func (meta *MetaPredicate) GetKeyAsFloat64(input dag.Filterable) (float64, bool)
func (*MetaPredicate) GetKeyAsString ¶
func (meta *MetaPredicate) GetKeyAsString(input dag.Filterable) (string, bool)
func (*MetaPredicate) GetKeyAsValue ¶
func (meta *MetaPredicate) GetKeyAsValue(input dag.Filterable) (any, bool)
Get the value from the `Filterable`.
This equates to `BoundObject.Descriptor.Field[key].Accessor` being called with `BoundObject.Binding`.
See `BoundObject.GetValue` for more.
func (*MetaPredicate) GetValueAsAny ¶
func (meta *MetaPredicate) GetValueAsAny() (any, bool)
func (*MetaPredicate) GetValueAsBool ¶
func (meta *MetaPredicate) GetValueAsBool() (bool, bool)
func (*MetaPredicate) GetValueAsComplex128 ¶
func (meta *MetaPredicate) GetValueAsComplex128() (complex128, bool)
func (*MetaPredicate) GetValueAsFloat64 ¶
func (meta *MetaPredicate) GetValueAsFloat64() (float64, bool)
func (*MetaPredicate) GetValueAsInt64 ¶
func (meta *MetaPredicate) GetValueAsInt64() (int64, bool)
func (*MetaPredicate) GetValueAsString ¶
func (meta *MetaPredicate) GetValueAsString() (string, bool)
Return the condition value as a string.
func (*MetaPredicate) GetValueAsUint64 ¶
func (meta *MetaPredicate) GetValueAsUint64() (uint64, bool)
func (*MetaPredicate) String ¶
func (meta *MetaPredicate) String(token string) string
type Reflectable ¶
type Reflectable interface {
// Return the reflected type for a given object.
//
// An example of how this could work is:
//
// “`go
// var (
// typeForYourStruct reflect.Type
// onceForYourStruct sync.Once
// )
//
// type YourStruct struct {
// // ...
// }
//
// func (ys *YourStruct) ReflectType() reflect.Type {
// onceForYourStruct.Do(func() {
// typeForYourStruct = reflect.TypeOf(ys).Elem()
// })
//
// return typeForYourStruct
// }
// “`
//
// You might need to do things differently for non-pointer types.
ReflectType() reflect.Type
}
type StructDescriptor ¶
func BuildDescriptor ¶
func BuildDescriptor(typ reflect.Type) *StructDescriptor
func NewStructDescriptor ¶
func NewStructDescriptor() *StructDescriptor
func (*StructDescriptor) Keys ¶
func (sd *StructDescriptor) Keys() []string
func (*StructDescriptor) String ¶
func (sd *StructDescriptor) String() string
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator structure.
func NewValidator ¶
Create a new validator with the default action set and predicate list.
func (*Validator) ClearFailures ¶
func (v *Validator) ClearFailures()
Clear the list of failure messages.
func (*Validator) CompileAction ¶
Compile an action from an action specification.
func (*Validator) CompileFailure ¶
Compile a failure action from a failure specification.
func (*Validator) Evaluate ¶
func (v *Validator) Evaluate(input dag.Filterable)
Evaluate an input against the validator.
Source Files
¶
- actions.go
- bindings.go
- bound.go
- fieldinfo.go
- predicate_fteq.go
- predicate_ftin.go
- predicate_fveq.go
- predicate_fvfalse.go
- predicate_fvgt.go
- predicate_fvgte.go
- predicate_fvin.go
- predicate_fvlt.go
- predicate_fvlte.go
- predicate_fvneq.go
- predicate_fvnil.go
- predicate_fvrem.go
- predicate_fvtrue.go
- predicates.go
- reflect.go
- reflectable.go
- structdescriptor.go
- validator.go