MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Example_cel_Compile

Function Example_cel_Compile

examples/example_cel_compile_test.go:26–43  ·  view source on GitHub ↗

Example_cel_Compile showcases compiling a CEL expression with variable declarations

()

Source from the content-addressed store, hash-verified

24
25// Example_cel_Compile showcases compiling a CEL expression with variable declarations
26func 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
46func Example_cel_Compile_options() {

Callers

nothing calls this directly

Calls 3

CompileFunction · 0.92
VariableFunction · 0.92
EvalMethod · 0.65

Tested by

no test coverage detected