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

Function Example_cel_MemberOverload

examples/example_cel_member_test.go:26–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24)
25
26func Example_cel_MemberOverload() {
27 env, err := cel.NewEnv(cel.Lib(customLib{}))
28 if err != nil {
29 log.Fatalf("environment creation error: %v\n", err)
30 }
31 // Check iss for error in both Parse and Check.
32 ast, iss := env.Compile(`i.greet(you)`)
33 if iss.Err() != nil {
34 log.Fatalln(iss.Err())
35 }
36 prg, err := env.Program(ast)
37 if err != nil {
38 log.Fatalf("Program creation error: %v\n", err)
39 }
40
41 out, _, err := prg.Eval(map[string]any{
42 "i": "CEL",
43 "you": "world",
44 })
45 if err != nil {
46 log.Fatalf("Evaluation error: %v\n", err)
47 }
48
49 fmt.Println(out)
50 // Output:Hello world! Nice to meet you, I'm CEL.
51}
52
53type customLib struct{}
54

Callers

nothing calls this directly

Calls 6

CompileMethod · 0.95
ProgramMethod · 0.95
NewEnvFunction · 0.92
LibFunction · 0.92
ErrMethod · 0.80
EvalMethod · 0.65

Tested by

no test coverage detected