github.com/Rookout/GoSDK@v0.1.48/pkg/augs/conditions/condition.go (about) 1 package conditions 2 3 import ( 4 "github.com/Rookout/GoSDK/pkg/processor/namespaces" 5 "github.com/Rookout/GoSDK/pkg/processor/paths" 6 "github.com/Rookout/GoSDK/pkg/rookoutErrors" 7 ) 8 9 type ConditionCreatorFunc func(string) (Condition, rookoutErrors.RookoutError) 10 11 type Condition interface { 12 Evaluate(namespace namespaces.Namespace) (bool, rookoutErrors.RookoutError) 13 } 14 15 type condition struct { 16 path paths.Path 17 } 18 19 func NewCondition(conditionString string) (Condition, rookoutErrors.RookoutError) { 20 path, err := paths.NewArithmeticPath(conditionString) 21 if err != nil { 22 return nil, err 23 } 24 return &condition{path: path}, nil 25 } 26 27 func (c *condition) Evaluate(namespace namespaces.Namespace) (bool, rookoutErrors.RookoutError) { 28 res, err := c.path.ReadFrom(namespace) 29 if err != nil { 30 return false, err 31 } 32 return res.GetObject().(bool), nil 33 }