google / cel-go

Fast, portable, non-Turing complete expression evaluation with gradual typing (Go)
https://cel.dev
Apache License 2.0
2.3k stars 224 forks source link

Allow configurable tag name overrides in native types #1009

Closed matthchr closed 2 months ago

matthchr commented 2 months ago

Allowing tags other than "cel" enables more flexibility, particularly when the types in question aren't owned by those configuring the CEL environment.

The main use-case for this is enabling an experience in CEL that matches the shape of an object in JSON (or YAML). This includes:

Reviews

Merging

google-cla[bot] commented 2 months ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

TristonianJones commented 2 months ago

Hi @matthchr, thanks for the contribution. Would you mind signing the CLA? I'll try to give this a review by the end of the week.

/gcbrun

matthchr commented 2 months ago

I've signed the CLA. Let me know if you have any questions as well - I'm happy to talk through our use-case. I had originally done a different approach, something like this:

type NativeFieldAdapter = func(rt reflect.Type, name string) (reflect.StructField, bool)

func defaultNativeFieldAdapter(rt reflect.Type, name string) (reflect.StructField, bool) {
    return rt.FieldByName(name)
}

that users could configure, before I realized that actually all I really needed was to be able to configure the tag to parse for the feature that already existed, because what I wanted to do was use JSON tags rather than a new CEL tag.

TristonianJones commented 2 months ago

/gcbrun

TristonianJones commented 2 months ago

/gcbrun

matthchr commented 2 months ago

Thanks for merging!