Documentation
¶
Overview ¶
Example (Jsonata) ¶
package main
import (
"fmt"
"log"
"github.com/arran4/lookup"
"github.com/arran4/lookup/jsonata"
)
func main() {
// 1. Data
data := map[string]interface{}{
"Account": map[string]interface{}{
"Name": "Firefly",
"Balance": 100.50,
},
}
// 2. Compile JSONata expression
// This uses the lookups JSONata compiler which binds functions at parse time.
ast, err := jsonata.Parse("Account.Name")
if err != nil {
log.Fatal(err)
}
q := jsonata.Compile(ast)
// 3. Execute
result := q.Run(&lookup.Scope{
Current: lookup.Reflect(data),
})
fmt.Println(result.Raw())
}
Output: Firefly
Example (JsonataCustomFunction) ¶
package main
import (
"fmt"
"log"
"github.com/arran4/go-evaluator"
"github.com/arran4/lookup"
"github.com/arran4/lookup/jsonata"
)
func main() {
// 1. Create a Context with standard functions and register custom one
// Thread-safe!
funcs := jsonata.GetStandardFunctions()
funcs["$greet"] = &GreetFunc{}
ctx := &evaluator.Context{
Functions: funcs,
}
// 2. Data
data := map[string]interface{}{
"Name": "Alice",
}
// 3. Compile expression using the custom function
ast, err := jsonata.Parse("$greet(Name)")
if err != nil {
log.Fatal(err)
}
q := jsonata.Compile(ast)
// 4. Run with Context
result := q.Run(lookup.NewScopeWithContext(nil, lookup.Reflect(data), ctx))
fmt.Println(result.Raw())
}
type GreetFunc struct{}
func (g *GreetFunc) Call(args ...interface{}) (interface{}, error) {
if len(args) == 0 {
return "Hello!", nil
}
name, ok := args[0].(string)
if !ok {
return nil, fmt.Errorf("arg 0 must be string")
}
return fmt.Sprintf("Hello, %s!", name), nil
}
Output: Hello, Alice!
Index ¶
- Variables
- func Add(left, right Runner) *addFunc
- func Any(e Runner) *anyFunc
- func Append(e Runner) *appendFunc
- func Chain(first, second Runner) *chainFunc
- func Contains(runner Runner) *containsFunc
- func Default(i interface{}) *otherwiseFunc
- func Divide(left, right Runner) *divideFunc
- func Equals(e Runner) *equalsFunc
- func Error(err error) *errorFunc
- func Every(e Runner) *everyFunc
- func ExtractPath(pather Pathor) string
- func FallbackPaths(paths ...string) *fallbackPathsFunc
- func Filter(expression Runner) *filterFunc
- func First(e Runner) *firstFunc
- func GreaterThan(e Runner) *evaluatorComparisonFunc
- func GreaterThanOrEqual(e Runner) *evaluatorComparisonFunc
- func If(cond Runner, then Runner, otherwise Runner) *ifFunc
- func In(e Runner) *inFunc
- func Index(i interface{}) *indexFunc
- func Intersection(e Runner) *intersectionFunc
- func IsZero(e Runner) *isZeroFunc
- func Last(e Runner) *lastFunc
- func LessThan(e Runner) *evaluatorComparisonFunc
- func LessThanOrEqual(e Runner) *evaluatorComparisonFunc
- func Map(expression Runner) *mapFunc
- func Match(e ...Runner) *matchFunc
- func Modulo(left, right Runner) *moduloFunc
- func Multiply(left, right Runner) *multiplyFunc
- func Not(e Runner) *notFunc
- func NotEquals(e Runner) *evaluatorComparisonFunc
- func PathBuilder(path string, r Pathor, cp CustomPath) string
- func Range(start, end interface{}) *rangeFunc
- func StringConcat(left, right Runner) *stringConcatFunc
- func Subtract(left, right Runner) *subtractFunc
- func ToBool(expression Runner) *toBoolFunc
- func ToFloat(i interface{}) (float64, bool)
- func ToInt(i interface{}) (int64, bool)
- func Truthy(expression Runner) *truthyFunc
- func Union(e Runner) *unionFunc
- type Constantor
- func (c *Constantor) AsBool() (bool, error)
- func (c *Constantor) AsFloat() (float64, error)
- func (c *Constantor) AsInt() (int64, error)
- func (c *Constantor) AsMap() (map[string]interface{}, error)
- func (c *Constantor) AsPtr() (interface{}, error)
- func (c *Constantor) AsSlice() ([]interface{}, error)
- func (c *Constantor) AsString() (string, error)
- func (r *Constantor) Find(path string, opts ...Runner) Pathor
- func (c *Constantor) IsBool() bool
- func (c *Constantor) IsFloat() bool
- func (c *Constantor) IsInt() bool
- func (c *Constantor) IsInterface() bool
- func (c *Constantor) IsMap() bool
- func (c *Constantor) IsNil() bool
- func (c *Constantor) IsPtr() bool
- func (c *Constantor) IsSlice() bool
- func (c *Constantor) IsString() bool
- func (c *Constantor) IsStruct() bool
- func (r *Constantor) Raw() interface{}
- func (r *Constantor) RawAsInterfaceSlice() []interface{}
- func (c *Constantor) Run(scope *Scope) Pathor
- func (r *Constantor) Type() reflect.Type
- func (r *Constantor) Value() reflect.Value
- type CustomPath
- type Finder
- type HasPath
- type Interface
- type Interfaceor
- func (i *Interfaceor) AsBool() (bool, error)
- func (i *Interfaceor) AsFloat() (float64, error)
- func (i *Interfaceor) AsInt() (int64, error)
- func (i *Interfaceor) AsMap() (map[string]interface{}, error)
- func (i *Interfaceor) AsPtr() (interface{}, error)
- func (i *Interfaceor) AsSlice() ([]interface{}, error)
- func (i *Interfaceor) AsString() (string, error)
- func (i *Interfaceor) Find(path string, opts ...Runner) Pathor
- func (i *Interfaceor) IsBool() bool
- func (i *Interfaceor) IsFloat() bool
- func (i *Interfaceor) IsInt() bool
- func (i *Interfaceor) IsInterface() bool
- func (i *Interfaceor) IsMap() bool
- func (i *Interfaceor) IsNil() bool
- func (i *Interfaceor) IsPtr() bool
- func (i *Interfaceor) IsSlice() bool
- func (i *Interfaceor) IsString() bool
- func (i *Interfaceor) IsStruct() bool
- func (i *Interfaceor) Path() string
- func (i *Interfaceor) Raw() interface{}
- func (i *Interfaceor) RawAsInterfaceSlice() []interface{}
- func (i *Interfaceor) Type() reflect.Type
- func (i *Interfaceor) Value() reflect.Value
- type Invalidor
- func (i *Invalidor) AsBool() (bool, error)
- func (i *Invalidor) AsFloat() (float64, error)
- func (i *Invalidor) AsInt() (int64, error)
- func (i *Invalidor) AsMap() (map[string]interface{}, error)
- func (i *Invalidor) AsPtr() (interface{}, error)
- func (i *Invalidor) AsSlice() ([]interface{}, error)
- func (i *Invalidor) AsString() (string, error)
- 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) IsBool() bool
- func (i *Invalidor) IsFloat() bool
- func (i *Invalidor) IsInt() bool
- func (i *Invalidor) IsInterface() bool
- func (i *Invalidor) IsMap() bool
- func (i *Invalidor) IsNil() bool
- func (i *Invalidor) IsPtr() bool
- func (i *Invalidor) IsSlice() bool
- func (i *Invalidor) IsString() bool
- func (i *Invalidor) IsStruct() bool
- func (i *Invalidor) Path() string
- func (i *Invalidor) Raw() interface{}
- func (i *Invalidor) RawAsInterfaceSlice() []interface{}
- func (i *Invalidor) Type() reflect.Type
- func (i *Invalidor) Unwrap() error
- func (i *Invalidor) Value() reflect.Value
- type Jsonor
- func (j *Jsonor) AsBool() (bool, error)
- func (j *Jsonor) AsFloat() (float64, error)
- func (j *Jsonor) AsInt() (int64, error)
- func (j *Jsonor) AsMap() (map[string]interface{}, error)
- func (j *Jsonor) AsPtr() (interface{}, error)
- func (j *Jsonor) AsSlice() ([]interface{}, error)
- func (j *Jsonor) AsString() (string, error)
- func (j *Jsonor) Find(path string, opts ...Runner) Pathor
- func (j *Jsonor) IsBool() bool
- func (j *Jsonor) IsFloat() bool
- func (j *Jsonor) IsInt() bool
- func (j *Jsonor) IsInterface() bool
- func (j *Jsonor) IsMap() bool
- func (j *Jsonor) IsNil() bool
- func (j *Jsonor) IsPtr() bool
- func (j *Jsonor) IsSlice() bool
- func (j *Jsonor) IsString() bool
- func (j *Jsonor) IsStruct() bool
- func (j *Jsonor) Path() string
- func (j *Jsonor) Raw() interface{}
- func (j *Jsonor) RawAsInterfaceSlice() []interface{}
- func (j *Jsonor) Type() reflect.Type
- func (j *Jsonor) Value() reflect.Value
- type Pathor
- type Reflector
- func (r *Reflector) AsBool() (bool, error)
- func (r *Reflector) AsFloat() (float64, error)
- func (r *Reflector) AsInt() (int64, error)
- func (r *Reflector) AsMap() (map[string]interface{}, error)
- func (r *Reflector) AsPtr() (interface{}, error)
- func (r *Reflector) AsSlice() ([]interface{}, error)
- func (r *Reflector) AsString() (string, error)
- func (r *Reflector) Find(path string, opts ...Runner) Pathor
- func (r *Reflector) IsBool() bool
- func (r *Reflector) IsFloat() bool
- func (r *Reflector) IsInt() bool
- func (r *Reflector) IsInterface() bool
- func (r *Reflector) IsMap() bool
- func (r *Reflector) IsNil() bool
- func (r *Reflector) IsPtr() bool
- func (r *Reflector) IsSlice() bool
- func (r *Reflector) IsString() bool
- func (r *Reflector) IsStruct() bool
- func (r *Reflector) Path() string
- func (r *Reflector) Raw() interface{}
- func (r *Reflector) RawAsInterfaceSlice() []interface{}
- func (r *Reflector) Type() reflect.Type
- func (r *Reflector) Value() reflect.Value
- type Relator
- type Runner
- type Scope
- type Simpleor
- func (s *Simpleor) AsBool() (bool, error)
- func (s *Simpleor) AsFloat() (float64, error)
- func (s *Simpleor) AsInt() (int64, error)
- func (s *Simpleor) AsMap() (map[string]interface{}, error)
- func (s *Simpleor) AsPtr() (interface{}, error)
- func (s *Simpleor) AsSlice() ([]interface{}, error)
- func (s *Simpleor) AsString() (string, error)
- func (s *Simpleor) Evaluate(scope *Scope, position Pathor) (Pathor, error)
- func (s *Simpleor) Find(path string, opts ...Runner) Pathor
- func (s *Simpleor) IsBool() bool
- func (s *Simpleor) IsFloat() bool
- func (s *Simpleor) IsInt() bool
- func (s *Simpleor) IsInterface() bool
- func (s *Simpleor) IsMap() bool
- func (s *Simpleor) IsNil() bool
- func (s *Simpleor) IsPtr() bool
- func (s *Simpleor) IsSlice() bool
- func (s *Simpleor) IsString() bool
- func (s *Simpleor) IsStruct() bool
- func (s *Simpleor) Path() string
- func (s *Simpleor) Raw() interface{}
- func (s *Simpleor) RawAsInterfaceSlice() []interface{}
- func (s *Simpleor) Type() reflect.Type
- func (s *Simpleor) Value() reflect.Value
- type Valuor
- type Yamlor
- func (y *Yamlor) AsBool() (bool, error)
- func (y *Yamlor) AsFloat() (float64, error)
- func (y *Yamlor) AsInt() (int64, error)
- func (y *Yamlor) AsMap() (map[string]interface{}, error)
- func (y *Yamlor) AsPtr() (interface{}, error)
- func (y *Yamlor) AsSlice() ([]interface{}, error)
- func (y *Yamlor) AsString() (string, error)
- func (y *Yamlor) Find(path string, opts ...Runner) Pathor
- func (y *Yamlor) IsBool() bool
- func (y *Yamlor) IsFloat() bool
- func (y *Yamlor) IsInt() bool
- func (y *Yamlor) IsInterface() bool
- func (y *Yamlor) IsMap() bool
- func (y *Yamlor) IsNil() bool
- func (y *Yamlor) IsPtr() bool
- func (y *Yamlor) IsSlice() bool
- func (y *Yamlor) IsString() bool
- func (y *Yamlor) IsStruct() bool
- func (y *Yamlor) Path() string
- func (y *Yamlor) Raw() interface{}
- func (y *Yamlor) RawAsInterfaceSlice() []interface{}
- func (y *Yamlor) Type() reflect.Type
- func (y *Yamlor) Value() reflect.Value
Examples ¶
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") // Type errors ErrNotString = errors.New("value is not a string") ErrNotInt = errors.New("value is not an int") ErrNotBool = errors.New("value is not a bool") ErrNotFloat = errors.New("value is not a float") ErrNotSlice = errors.New("value is not a slice") ErrNotMap = errors.New("value is not a map") ErrNotStruct = errors.New("value is not a struct") ErrNotPtr = errors.New("value is not a pointer") ErrNotInterface = errors.New("value is not an interface") )
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 FallbackPaths ¶ added in v1.0.2
func FallbackPaths(paths ...string) *fallbackPathsFunc
func GreaterThan ¶ added in v1.0.3
func GreaterThan(e Runner) *evaluatorComparisonFunc
func GreaterThanOrEqual ¶ added in v1.0.3
func GreaterThanOrEqual(e Runner) *evaluatorComparisonFunc
func Intersection ¶
func Intersection(e Runner) *intersectionFunc
func LessThanOrEqual ¶ added in v1.0.3
func LessThanOrEqual(e Runner) *evaluatorComparisonFunc
func PathBuilder ¶
func PathBuilder(path string, r Pathor, cp CustomPath) string
func StringConcat ¶ added in v1.0.3
func StringConcat(left, right Runner) *stringConcatFunc
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) AsBool ¶ added in v1.0.2
func (c *Constantor) AsBool() (bool, error)
func (*Constantor) AsFloat ¶ added in v1.0.2
func (c *Constantor) AsFloat() (float64, error)
func (*Constantor) AsInt ¶ added in v1.0.2
func (c *Constantor) AsInt() (int64, error)
func (*Constantor) AsMap ¶ added in v1.0.2
func (c *Constantor) AsMap() (map[string]interface{}, error)
func (*Constantor) AsPtr ¶ added in v1.0.2
func (c *Constantor) AsPtr() (interface{}, error)
func (*Constantor) AsSlice ¶ added in v1.0.2
func (c *Constantor) AsSlice() ([]interface{}, error)
func (*Constantor) AsString ¶ added in v1.0.2
func (c *Constantor) AsString() (string, error)
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) IsBool ¶ added in v1.0.2
func (c *Constantor) IsBool() bool
func (*Constantor) IsFloat ¶ added in v1.0.2
func (c *Constantor) IsFloat() bool
func (*Constantor) IsInt ¶ added in v1.0.2
func (c *Constantor) IsInt() bool
func (*Constantor) IsInterface ¶ added in v1.0.2
func (c *Constantor) IsInterface() bool
func (*Constantor) IsMap ¶ added in v1.0.2
func (c *Constantor) IsMap() bool
func (*Constantor) IsNil ¶ added in v1.0.2
func (c *Constantor) IsNil() bool
func (*Constantor) IsPtr ¶ added in v1.0.2
func (c *Constantor) IsPtr() bool
func (*Constantor) IsSlice ¶ added in v1.0.2
func (c *Constantor) IsSlice() bool
func (*Constantor) IsString ¶ added in v1.0.2
func (c *Constantor) IsString() bool
func (*Constantor) IsStruct ¶ added in v1.0.2
func (c *Constantor) IsStruct() bool
func (*Constantor) Raw ¶
func (r *Constantor) Raw() interface{}
Raw returns the contained object / reference.
func (*Constantor) RawAsInterfaceSlice ¶ added in v1.0.2
func (r *Constantor) RawAsInterfaceSlice() []interface{}
RawAsInterfaceSlice returns the contained object as a slice of interface{}.
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 wrapping element for the Interface component to make it adhere to the Pathor interface
func (*Interfaceor) AsBool ¶ added in v1.0.2
func (i *Interfaceor) AsBool() (bool, error)
func (*Interfaceor) AsFloat ¶ added in v1.0.2
func (i *Interfaceor) AsFloat() (float64, error)
func (*Interfaceor) AsInt ¶ added in v1.0.2
func (i *Interfaceor) AsInt() (int64, error)
func (*Interfaceor) AsMap ¶ added in v1.0.2
func (i *Interfaceor) AsMap() (map[string]interface{}, error)
func (*Interfaceor) AsPtr ¶ added in v1.0.2
func (i *Interfaceor) AsPtr() (interface{}, error)
func (*Interfaceor) AsSlice ¶ added in v1.0.2
func (i *Interfaceor) AsSlice() ([]interface{}, error)
func (*Interfaceor) AsString ¶ added in v1.0.2
func (i *Interfaceor) AsString() (string, error)
func (*Interfaceor) IsBool ¶ added in v1.0.2
func (i *Interfaceor) IsBool() bool
func (*Interfaceor) IsFloat ¶ added in v1.0.2
func (i *Interfaceor) IsFloat() bool
func (*Interfaceor) IsInt ¶ added in v1.0.2
func (i *Interfaceor) IsInt() bool
func (*Interfaceor) IsInterface ¶ added in v1.0.2
func (i *Interfaceor) IsInterface() bool
func (*Interfaceor) IsMap ¶ added in v1.0.2
func (i *Interfaceor) IsMap() bool
func (*Interfaceor) IsNil ¶ added in v1.0.2
func (i *Interfaceor) IsNil() bool
func (*Interfaceor) IsPtr ¶ added in v1.0.2
func (i *Interfaceor) IsPtr() bool
func (*Interfaceor) IsSlice ¶ added in v1.0.2
func (i *Interfaceor) IsSlice() bool
func (*Interfaceor) IsString ¶ added in v1.0.2
func (i *Interfaceor) IsString() bool
func (*Interfaceor) IsStruct ¶ added in v1.0.2
func (i *Interfaceor) IsStruct() bool
func (*Interfaceor) Path ¶
func (i *Interfaceor) Path() string
func (*Interfaceor) Raw ¶
func (i *Interfaceor) Raw() interface{}
func (*Interfaceor) RawAsInterfaceSlice ¶ added in v1.0.2
func (i *Interfaceor) RawAsInterfaceSlice() []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.
func (*Invalidor) IsInterface ¶ added in v1.0.2
func (*Invalidor) RawAsInterfaceSlice ¶ added in v1.0.2
func (i *Invalidor) RawAsInterfaceSlice() []interface{}
RawAsInterfaceSlice returns nil
type Jsonor ¶
type Jsonor struct {
// contains filtered or unexported fields
}
Jsonor is a Pathor that lazily unmarshals JSON bytes when accessed.
func (*Jsonor) IsInterface ¶ added in v1.0.2
func (*Jsonor) RawAsInterfaceSlice ¶ added in v1.0.2
func (j *Jsonor) RawAsInterfaceSlice() []interface{}
RawAsInterfaceSlice returns the decoded value as a slice of interface{}.
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{}
// RawAsInterfaceSlice returns the raw contents as a slice of interface{}. If the value is not a slice it returns nil.
RawAsInterfaceSlice() []interface{}
// Type returns the reflect.Type or nil. This could be restricted to lookup.Reflector and others where appropriate
Type() reflect.Type
// IsString returns true if the underlying value is a string
IsString() bool
// IsInt returns true if the underlying value is an int (int, int8, int16, int32, int64)
IsInt() bool
// IsBool returns true if the underlying value is a bool
IsBool() bool
// IsFloat returns true if the underlying value is a float (float32, float64)
IsFloat() bool
// IsSlice returns true if the underlying value is a slice or array
IsSlice() bool
// IsMap returns true if the underlying value is a map
IsMap() bool
// IsStruct returns true if the underlying value is a struct
IsStruct() bool
// IsNil returns true if the underlying value is nil
IsNil() bool
// IsPtr returns true if the underlying value is a pointer
IsPtr() bool
// IsInterface returns true if the underlying value is an interface
IsInterface() bool
// AsString returns the string value or error if not a string
AsString() (string, error)
// AsInt returns the int value (as int64) or error if not an int
AsInt() (int64, error)
// AsBool returns the bool value or error if not a bool
AsBool() (bool, error)
// AsFloat returns the float value (as float64) or error if not a float
AsFloat() (float64, error)
// AsSlice returns the slice value as []interface{} or error if not a slice
AsSlice() ([]interface{}, error)
// AsMap returns the map value as map[string]interface{} or error if not a map (or keys are not strings)
AsMap() (map[string]interface{}, error)
// AsPtr returns the pointer value or error if not a pointer
AsPtr() (interface{}, error)
}
Pathor interface
func NewInterfaceor ¶
NewInterfaceor see Interface and Interfaceor for details.
func QuerySimplePath ¶
QuerySimplePath executes the given simple path query string against the provided value using reflection.
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) IsInterface ¶ added in v1.0.2
func (*Reflector) Raw ¶
func (r *Reflector) Raw() interface{}
Raw returns the contained object / reference.
func (*Reflector) RawAsInterfaceSlice ¶ added in v1.0.2
func (r *Reflector) RawAsInterfaceSlice() []interface{}
RawAsInterfaceSlice returns the contained object as a slice of interface{}.
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
func ParseSimplePath ¶
ParseSimplePath converts a simple query string like "A.B[0].C" into a Relator which can be run against any Pathor. The supported syntax only understands dot separated field lookups and integer based indexes using square brackets.
type Scope ¶
type Scope struct {
Current Pathor
Parent *Scope
Position Pathor
Context *evaluator.Context
// contains filtered or unexported fields
}
func NewScopeWithContext ¶ added in v1.0.3
type Simpleor ¶
type Simpleor struct {
// contains filtered or unexported fields
}
Simpleor is a Pathor implementation that uses type switches for common types (map[string]interface{}, []interface{}) to avoid reflection overhead where possible.
func (*Simpleor) IsInterface ¶ added in v1.0.2
func (*Simpleor) RawAsInterfaceSlice ¶ added in v1.0.2
func (s *Simpleor) RawAsInterfaceSlice() []interface{}
type Yamlor ¶
type Yamlor struct {
// contains filtered or unexported fields
}
Yamlor is a Pathor that lazily unmarshals YAML bytes when accessed.
func (*Yamlor) IsInterface ¶ added in v1.0.2
func (*Yamlor) RawAsInterfaceSlice ¶ added in v1.0.2
func (y *Yamlor) RawAsInterfaceSlice() []interface{}
RawAsInterfaceSlice returns the decoded value as a slice of interface{}.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
json-simpe-path
command
|
|
|
yaml-simpe-path
command
|
|
|
advanced
command
|
|
|
collections
command
|
|
|
interfacor1
command
|
|