You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 25, 2025. It is now read-only.
package main
import (
"fmt"
"github.com/Knetic/govaluate"
)
func main() {
funcs := map[string]govaluate.ExpressionFunction{
"yes": func(args ...interface{}) (interface{}, error) {
fmt.Println("should execute", args)
return nil, nil
},
"no": func(args ...interface{}) (interface{}, error) {
fmt.Println("should NOT execute", args)
return nil, nil
},
}
str := ` [var] == true ? yes('good') : no ('bad')`
exp, e := govaluate.NewEvaluableExpressionWithFunctions(str, funcs)
if e != nil {
fmt.Println(e)
}
vars := map[string]interface{}{
"var": true,
}
fmt.Println("----Exec with value is true----")
exp.Evaluate(vars)
fmt.Println("----Exec with value is false----")
vars["var"] = false
exp.Evaluate(vars)
}
----Exec with value is true----
should execute [good]
should NOT execute [bad]
----Exec with value is false----
should NOT execute [bad]
Program exited.