Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document cel.Constant environment option #920

Open
brigitops opened this issue Apr 8, 2024 · 0 comments
Open

document cel.Constant environment option #920

brigitops opened this issue Apr 8, 2024 · 0 comments
Assignees

Comments

@brigitops
Copy link

brigitops commented Apr 8, 2024

I'm finding it hard to figure out how to use the cel.Constant environment option. As it is an environment option, I assume it is intended for general use and not as an internal feature?

For cel.Variable, examples abound, such as this from the main README:

import "github.com/google/cel-go/cel"

env, err := cel.NewEnv(
    cel.Variable("name", cel.StringType),
    cel.Variable("group", cel.StringType),
)

The same is not true of cel.Constant. A thorough search of the internet, for various combinations such as "cel-go", "common expression language", "Constant", "cel.Constant", and a bunch of others I tried, all find very little to explain this feature.

I tried to guess at it, but ref.Val has me unsure:

import "github.com/google/cel-go/cel"

env, err := cel.NewEnv(
    cel.Constant("name", cel.StringType, "how to create a valid ref.Val?"), // this won't compile, as ref.Val isn't a string type
)

What is the safe, intended way in which I should create a ref.Val for a primitive type such as a string or int?

Also, are constants automatically optimized by evaluating them at compile-time?

I've raised this as an issue rather than discussion, since I think it will help other uses if the answer becomes documentation.

@TristonianJones TristonianJones self-assigned this Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants