Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const ArrowOperator = "=>"
Variables ¶
View Source
var ( ErrDecisionDenied = errors.New("trigger: evaluation = false") ErrEmptyExpressions = errors.New("trigger: empty expressions") )
View Source
var ErrArrowOperator = errors.Errorf("arrow operator: expecting syntax ${decision} %s ${mutation}", ArrowOperator)
View Source
var Functions = FuncMap{ "now": { // contains filtered or unexported fields }, "uuid": { // contains filtered or unexported fields }, "sha1": { // contains filtered or unexported fields }, "sha256": { // contains filtered or unexported fields }, "sha3": { // contains filtered or unexported fields }, "base64Encode": { // contains filtered or unexported fields }, "base64Decode": { // contains filtered or unexported fields }, "jsonEncode": { // contains filtered or unexported fields }, "jsonDecode": { // contains filtered or unexported fields }, "replace": { // contains filtered or unexported fields }, "join": { // contains filtered or unexported fields }, "titleCase": { // contains filtered or unexported fields }, "lowerCase": { // contains filtered or unexported fields }, "upperCase": { // contains filtered or unexported fields }, "trimSpace": { // contains filtered or unexported fields }, "trimPrefix": { // contains filtered or unexported fields }, "trimSuffix": { // contains filtered or unexported fields }, "geoDistance": { // contains filtered or unexported fields }, "render": { // contains filtered or unexported fields }, "parseClaims": { // contains filtered or unexported fields }, "parseHeader": { // contains filtered or unexported fields }, "parseSignature": { // contains filtered or unexported fields }, "typeOf": { // contains filtered or unexported fields }, "encrypt": { // contains filtered or unexported fields }, "decrypt": { // contains filtered or unexported fields }, "parseHost": { // contains filtered or unexported fields }, "parseQuery": { // contains filtered or unexported fields }, "parsePath": { // contains filtered or unexported fields }, "parseScheme": { // contains filtered or unexported fields }, "split": { // contains filtered or unexported fields }, "trimRight": { // contains filtered or unexported fields }, "trimLeft": { // contains filtered or unexported fields }, }
Functions ¶
This section is empty.
Types ¶
type Decision ¶
type Decision struct {
// contains filtered or unexported fields
}
Decision is used to evaluate boolean expressions
func NewDecision ¶
NewDecision creates a new Decision with the given boolean CEL expressions
Example ¶
package main import ( "fmt" "github.com/graphikDB/trigger" ) func main() { decision, err := trigger.NewDecision("this.email.endsWith('acme.com')") if err != nil { fmt.Println(err.Error()) return } err = decision.Eval(map[string]interface{}{ "email": "bob@gmail.com", }) fmt.Println(err == trigger.ErrDecisionDenied) }
Output: true
func (*Decision) Expression ¶
Expressions returns the decsions raw expression
type Trigger ¶
type Trigger struct {
// contains filtered or unexported fields
}
Trigger creates values as map[string]interface{} if it's decisider returns no errors against a Mapper
func NewArrowTrigger ¶ added in v0.0.14
NewArrowTrigger creates a trigger from arrow syntax ${decision} => ${mutation}
func NewTrigger ¶
NewTrigger creates a new trigger instance from the decision & trigger expressions
Example ¶
package main import ( "fmt" "github.com/graphikDB/trigger" ) func main() { // create a trigger based on the new decision that hashes a password and creates an updated_at timestamp // this would in theory be applied to a newly created user after signup trigg, err := trigger.NewArrowTrigger(` this.event == 'signup' && has(this.email) => { 'updated_at': now(), 'password': this.password.sha1() } `) if err != nil { fmt.Println(err.Error()) return } user := map[string]interface{}{ "event": "signup", "name": "bob", "email": "bob@acme.com", "password": "123456", } data, err := trigg.Trigger(user) if err != nil { fmt.Println(err.Error()) return } fmt.Println(data["updated_at"].(int64) > 0, data["password"]) }
Output: true 7c4a8d09ca3762af61e59520943dc26494f8941b
func (*Trigger) Expression ¶
Expression returns the triggers raw CEL expressions
Click to show internal directories.
Click to hide internal directories.