Closed
Description
Description: Similar to what other Go libraries provide, it would be nice that in expr we could ignore a struct field in the environment if the field has a struct tag expr:"-"
.
Example happening in other libraries: in the standard library the package encoding/json
ignores struct fields that have the struct tag json:"-"
, causing it to neither encode nor decode those fields.
Use case: reusing the same struct to avoid tedious copying that is error-prone.
Example of proposed feature:
type MyEnv struct {
VisibleField string
HiddenField string `expr:"-"`
}
func main() {
_, err := expr.Eval(`HiddenField`, MyEnv{})
// we would get a `cannot fetch HiddenField` error
}
P.S.: I have created PR #806 as an example of how the feature could be implemented. Please, let me know if you would rather discuss a different approach if you think this proposal makes sense.
Thank you :)