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

Function eval

codelab/solution/codelab.go:404–434  ·  view source on GitHub ↗

eval will evaluate a given program `prg` against a set of variables `vars` and return the output, eval details (optional), or error that results from evaluation.

(prg cel.Program,
	vars any)

Source from the content-addressed store, hash-verified

402// and return the output, eval details (optional), or error that results from
403// evaluation.
404func eval(prg cel.Program,
405 vars any) (out ref.Val, det *cel.EvalDetails, err error) {
406 varMap, isMap := vars.(map[string]any)
407 fmt.Println("------ input ------")
408 if !isMap {
409 fmt.Printf("(%T)\n", vars)
410 } else {
411 for k, v := range varMap {
412 switch val := v.(type) {
413 case proto.Message:
414 bytes, err := prototext.Marshal(val)
415 if err != nil {
416 glog.Exitf("failed to marshal proto to text: %v", val)
417 }
418 fmt.Printf("%s = %s", k, string(bytes))
419 case map[string]any:
420 b, _ := json.MarshalIndent(v, "", " ")
421 fmt.Printf("%s = %v\n", k, string(b))
422 case uint64:
423 fmt.Printf("%s = %vu\n", k, v)
424 default:
425 fmt.Printf("%s = %v\n", k, v)
426 }
427 }
428 }
429 fmt.Println()
430 out, det, err = prg.Eval(vars)
431 report(out, det, err)
432 fmt.Println()
433 return
434}
435
436// report prints out the result of evaluation in human-friendly terms.
437func report(result ref.Val, details *cel.EvalDetails, err error) {

Callers 8

exercise1Function · 0.70
exercise2Function · 0.70
exercise3Function · 0.70
exercise4Function · 0.70
exercise5Function · 0.70
exercise6Function · 0.70
exercise7Function · 0.70
exercise8Function · 0.70

Calls 2

reportFunction · 0.70
EvalMethod · 0.65

Tested by

no test coverage detected