-
Hi All, here is my code with the issue: I can store the compiled programs in an any slice, but I'm not able to assert to type *expr.Program or *vm.Program because neither are accessible/public to use. I'd appreciate any advice or help, Rhett |
Beta Was this translation helpful? Give feedback.
Answered by
antonmedv
Dec 23, 2024
Replies: 1 comment 1 reply
-
https://go.dev/play/p/FRHiy-r3RwI package main
import (
"fmt"
"log"
"github.com/expr-lang/expr"
+ "github.com/expr-lang/expr/vm"
)
func main() {
fmt.Println("main start")
env := map[string]any{
"creditScore": 810,
}
expressions := []string{
"creditScore >= 700",
"creditScore >= 680",
"creditScore >= 1000",
}
var programs []*vm.Program
for _, exprStr := range expressions {
program, err := expr.Compile(exprStr)
if err != nil {
log.Fatalf("failed to compile expression: %s", exprStr)
}
programs = append(programs, program)
}
for _, program := range programs {
result, err := expr.Run(program, env)
if err != nil {
fmt.Println("error evaluating...")
}
fmt.Println("the result is: ", result)
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
x1c1cle
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://go.dev/play/p/FRHiy-r3RwI
package main import ( "fmt" "log" "github.com/expr-lang/expr" + "github.com/expr-lang/expr/vm" ) func main() { fmt.Println("main start") env := map[string]any{ "creditScore": 810, } expressions := []string{ "creditScore >= 700", "creditScore >= 680", "creditScore >= 1000", } var programs []*vm.Program for _, exprStr := range expressions { program, err := expr.Compile(exprStr) if err != nil { log.Fatalf("failed to compile expression: %s", exprStr) } programs = append(programs, program) } for _, program := range programs { result, err := expr.Run(program, env) if err != nil { fmt.Println("error evaluating...") …