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)
| 402 | // and return the output, eval details (optional), or error that results from |
| 403 | // evaluation. |
| 404 | func 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. |
| 437 | func report(result ref.Val, details *cel.EvalDetails, err error) { |