Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrDecisionDenied = errors.New("eval: evaluation = false") ErrNoExpressions = errors.New("eval: no expressions") )
Functions ¶
This section is empty.
Types ¶
type Decision ¶ added in v0.0.1
type Decision struct {
// contains filtered or unexported fields
}
Decision is used to evaluate boolean expressions
func NewDecision ¶ added in v0.0.1
NewDecision creates a new Decision with the given boolean CEL expressions
Example ¶
package main
import (
"fmt"
"github.com/graphikDB/eval"
"strings"
)
func main() {
decision, err := eval.NewDecision([]string{"this.email.endsWith('acme.com')"})
if err != nil {
fmt.Println(err.Error())
return
}
if err := decision.AddExpression("this.name != ''"); err != nil {
fmt.Println(err.Error())
return
}
if err := decision.Eval(eval.MapperFunc(func() map[string]interface{} {
return map[string]interface{}{
"name": "bob",
"email": "bob@acme.com",
}
}), eval.AllTrue); err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(strings.Join(decision.Expressions(), ","))
}
Output: this.email.endsWith('acme.com'),this.name != ''
func (*Decision) AddExpression ¶ added in v0.0.1
AddExpression adds an expression to the decision tree
func (*Decision) Eval ¶ added in v0.0.1
func (n *Decision) Eval(mapper Mapper, typ DecisionType) error
Eval evaluates the boolean CEL expressions against the Mapper
func (*Decision) Expressions ¶ added in v0.0.1
Expressions returns the decsions raw expressions
type DecisionType ¶ added in v0.0.1
type DecisionType int
const ( AllTrue DecisionType = 0 AnyTrue DecisionType = 1 )
type Mapper ¶
type Mapper interface {
AsMap() map[string]interface{}
}
Mapper returns it's values as a map[string]interface{}
type MapperFunc ¶
type MapperFunc func() map[string]interface{}
MapperFunc implements Mapper
func (MapperFunc) AsMap ¶
func (m MapperFunc) AsMap() map[string]interface{}
Click to show internal directories.
Click to hide internal directories.