Documentation ¶
Index ¶
- Variables
- func Any(e Runner) *anyFunc
- func Contains(runner Runner) *containsFunc
- func Default(i interface{}) *otherwiseFunc
- func Equals(e Runner) *equalsFunc
- func Every(e Runner) *everyFunc
- func ExtractPath(pather Pathor) string
- func Filter(expression Runner) *filterFunc
- func In(e Runner) *inFunc
- func Index(i interface{}) *indexFunc
- func IsZero(e Runner) *isZeroFunc
- func Map(expression Runner) *mapFunc
- func Match(e ...Runner) *matchFunc
- func Not(e Runner) *notFunc
- func PathBuilder(path string, r Pathor, cp CustomPath) string
- func ToBool(expression Runner) *toBoolFunc
- func Truthy(expression Runner) *truthyFunc
- type Constantor
- type CustomPath
- type Finder
- type HasPath
- type Interface
- type Interfaceor
- type Invalidor
- func (i *Invalidor) Error() string
- func (i *Invalidor) Evaluate(scope *Scope, position Pathor) (Pathor, error)
- func (i *Invalidor) Find(path string, opts ...Runner) Pathor
- func (i *Invalidor) Path() string
- func (i *Invalidor) Raw() interface{}
- func (i *Invalidor) Type() reflect.Type
- func (i *Invalidor) Unwrap() error
- func (i *Invalidor) Value() reflect.Value
- type Pathor
- type Reflector
- type Relator
- type Runner
- type Scope
- type Valuor
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoSuchPath = errors.New("no such path") ErrInvalidEvaluationFunction = errors.New("invalid evaluation function") ErrEvalFail = errors.New("path succeeded but evaluator failed") ErrMatchFail = errors.New("path succeeded match failed") ErrIndexOfNotArray = errors.New("tried to index a non-array") ErrIndexValueNotValid = errors.New("index value not valid") ErrUnknownIndexMode = errors.New("unknown index mode") ErrIndexOutOfRange = errors.New("index out of range") ErrValueNotIn = errors.New("value not in set") ErrNoMatchesForQuery = errors.New("nothing matched query") ErrFalse = errors.New("evaluated to false") )
Functions ¶
func Default ¶
func Default(i interface{}) *otherwiseFunc
Default used with .Find() as a PathOpt this will will fallback / default to the provided value regardless of future nagivations, it suppresses most errors / Invalidators.
func ExtractPath ¶
ExtractPath retrieves the path use because I didn't export it.
func PathBuilder ¶
func PathBuilder(path string, r Pathor, cp CustomPath) string
Types ¶
type Constantor ¶
type Constantor struct {
// contains filtered or unexported fields
}
Constantor This object represents a non-navigable constant. It can be used as an argument applied on the appropriate location in a .Find() chain and it will be the fallback value if no value is found. It can be constructed with either lookup.NewConstantor or lookup.Default()
func Array ¶
func Array(c ...interface{}) *Constantor
func Constant ¶
func Constant(c interface{}) *Constantor
func False ¶
func False(path string) *Constantor
func NewConstantor ¶
func NewConstantor(path string, c interface{}) *Constantor
NewConstantor constructs a non-navigable constant.
func True ¶
func True(path string) *Constantor
func (*Constantor) Find ¶
func (r *Constantor) Find(path string, opts ...Runner) Pathor
Find returns a new Constinator with the same object but with an updated path if required.
func (*Constantor) Raw ¶
func (r *Constantor) Raw() interface{}
Raw returns the contained object / reference.
func (*Constantor) Run ¶
func (c *Constantor) Run(scope *Scope) Pathor
func (*Constantor) Type ¶
func (r *Constantor) Type() reflect.Type
Type extracts the reflect.Type from the stored object
func (*Constantor) Value ¶
func (r *Constantor) Value() reflect.Value
Value returns the reflect.Value
type CustomPath ¶
type Finder ¶
type Finder interface { // Find preforms a path navigation. 'Path' is either a map key, array/slice index, or struct function/field. // This function is fixed and will probably not change in the future // So usage is supposed to be changed, anything which implements this function should return null-safe values. (ie non // nul.) // Usage: `lookup.Reflector(MyObjcet).Find("Quotes").Find("12").Find("Qty").Raw() Find(path string, opts ...Runner) Pathor }
type HasPath ¶
type HasPath interface {
Path() string
}
HasPath is an interface used to determine if a Pathor has a Path() function
type Interface ¶
type Interface interface { // Find the next component.. Must return an Interface OR another type of Pathor. Get(path string) (interface{}, error) // The raw type Raw() interface{} }
Interface an interface you can implement to avoid using Reflector or to put your own selection logic such as if you were to run this over another data structure.
type Interfaceor ¶
type Interfaceor struct {
// contains filtered or unexported fields
}
Interfaceor the warping element for the Interface component to make it adhere to the Pathor interface
func (*Interfaceor) Path ¶
func (i *Interfaceor) Path() string
func (*Interfaceor) Raw ¶
func (i *Interfaceor) Raw() interface{}
func (*Interfaceor) Type ¶
func (i *Interfaceor) Type() reflect.Type
func (*Interfaceor) Value ¶
func (i *Interfaceor) Value() reflect.Value
type Invalidor ¶
type Invalidor struct {
// contains filtered or unexported fields
}
Invalidor indicates an invalid state this can be because of an error, or an invalid path. It contains an error and adheres to errors and errors.Unwrap using fmt.Errors(".. %w..") It is designed to be continued to be used without returning a null value when you reach an error and also provide the path and error combo for debugging. It is fully adherent to a Pathor object
func NewInvalidor ¶
NewInvalidor creates an invalidator, there shouldn't be any real reason to do this but you have an option to. See documentation for Invalidor for details
func (*Invalidor) Find ¶
Find returns a new Invalidator with the same object but with an updated path if required. -- The path changing component might be removed - or become toggleable in an option.
type Pathor ¶
type Pathor interface { // Finder preforms a path navigation. 'Path' is either a map key, array/slice index, or struct function/field. // This function is fixed and will probably not change in the future // So usage is supposed to be changed, anything which implements this function should return null-safe values. (ie non // nul.) // Usage: `lookup.Reflector(MyObjcet).Find("Quotes").Find("12").Find("Qty").Raw() Finder // Value returns the reflect.Value or an invalid reflect.Value. This could be restricted to lookup.Reflector and others where appropriate Value() reflect.Value // Raw returns the raw contents / result of the lookup. This won't change Raw() interface{} // Type returns the reflect.Type or nil. This could be restricted to lookup.Reflector and others where appropriate Type() reflect.Type }
Pathor interface
func NewInterfaceor ¶
NewInterfaceor see Interface and Interfaceor for details.
type Reflector ¶
type Reflector struct {
// contains filtered or unexported fields
}
Reflector is a Pathor which uses reflection for navigation of the the objects, it supports a wide range of elements
func (*Reflector) Find ¶
Find finds the best match for the "Path" argument in the contained object and then returns a Pathor for that location Match nothing was found it will return an Invalidor, or if a Constant has bee provided as an argument (such as through `Default()` it will default to that in most cases. Find is designed to return null safe results.
func (*Reflector) Raw ¶
func (r *Reflector) Raw() interface{}
Raw returns the contained object / reference.
type Relator ¶
type Relator struct {
// contains filtered or unexported fields
}
Relator allows you to do an Evaluate from a relative location
func NewRelator ¶
func NewRelator() *Relator