cel-go icon indicating copy to clipboard operation
cel-go copied to clipboard

Add support for struct tag name overrides in native types

Open patrickpichler opened this issue 1 year ago • 3 comments

In order to customize how to fields of native types can be accessed via CEL, struct tag support has been added. It is now possible to provide a struct field tag, that will act as the name for the corresponding field.

Here an example

type Person struct {
  Name string
  Age  int `cel:"age"`
}

and here is how to access the Age field from CEL:

person.age

Pull Requests Guidelines

See CONTRIBUTING.md for more details about when to create a GitHub Pull Request and when other kinds of contributions or consultation might be more desirable.

When creating a new pull request, please fork the repo and work within a development branch.

Commit Messages

  • Most changes should be accompanied by tests.
  • Commit messages should explain why the changes were made.
Summary of change in 50 characters or less

Background on why the change is being made with additional detail on
consequences of the changes elsewhere in the code or to the general
functionality of the library. Multiple paragraphs may be used, but
please keep lines to 72 characters or less.

Reviews

  • Perform a self-review.
  • Make sure the Travis CI build passes.
  • Assign a reviewer once both the above have been completed.

Merging

  • If a CEL maintaner approves the change, it may be merged by the author if they have write access. Otherwise, the change will be merged by a maintainer.
  • Multiple commits should be squashed before merging.
  • Please append the line closes #<issue-num>: description in the merge message, if applicable.

patrickpichler avatar May 13 '24 07:05 patrickpichler

/gcbrun

TristonianJones avatar May 13 '24 14:05 TristonianJones

Thanks @patrickpichler! This seems like a very nice win.

TristonianJones avatar May 13 '24 14:05 TristonianJones

Wow I just discovered this PR after creating #942! My PR fixes an issue not fixed in yours but completely related to the same use-case

quantumsheep avatar May 15 '24 10:05 quantumsheep

@TristonianJones I've updated the code, would be nice if you could have another look :)

patrickpichler avatar May 21 '24 07:05 patrickpichler

/gcbrun

TristonianJones avatar May 21 '24 18:05 TristonianJones

@patrickpichler thanks for the contribution!

TristonianJones avatar May 21 '24 18:05 TristonianJones