Skip to content
Discussion options

You must be logged in to vote

cel.Function/cel.Overload bindings only receive their arguments, not the activation, so a binding that closes over a per-call activation cannot be reused safely. That is why you end up creating a new env on every invocation.

Build the env once and pass the context as an ordinary CEL value instead:

ctxType := cel.MapType(cel.StringType, cel.DynType) // or a registered object type
env, _ := cel.NewEnv(
    cel.Variable("ctx", ctxType),
    cel.Function("someFuncWithCtx",
        cel.Overload("someFunc_with_ctx", []*cel.Type{ctxType, cel.StringType}, cel.DynType,
            cel.BinaryBinding(func(ctx, filter ref.Val) ref.Val {
                // read the per-call context from ctx and comput…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@vivshankar
Comment options

Answer selected by vivshankar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants