Example_cel_Compile showcases compiling a CEL expression with variable declarations
()
| 24 | |
| 25 | // Example_cel_Compile showcases compiling a CEL expression with variable declarations |
| 26 | func Example_cel_Compile() { |
| 27 | prg, err := cel.Compile(`"Hello world! I'm " + name + "."`, |
| 28 | cel.Variable("name", cel.StringType), |
| 29 | ) |
| 30 | if err != nil { |
| 31 | log.Fatalf("cel.Compile() failed: %v", err) |
| 32 | } |
| 33 | out, _, err := prg.Eval(map[string]any{ |
| 34 | "name": "CEL", |
| 35 | }) |
| 36 | if err != nil { |
| 37 | log.Fatalf("prg.Eval() failed: %v", err) |
| 38 | } |
| 39 | fmt.Println(out) |
| 40 | |
| 41 | // Output: |
| 42 | // Hello world! I'm CEL. |
| 43 | } |
| 44 | |
| 45 | // Example_cel_Compile_options showcases cel.Compile with extension options and multiple variables |
| 46 | func Example_cel_Compile_options() { |