expr icon indicating copy to clipboard operation
expr copied to clipboard

Normalizing exported struct fields

Open dpogorzelski opened this issue 4 years ago • 4 comments

Hey there :) Please consider the following:

type Instance struct {
	PublicAddress  string
	PrivateAddress string
	Name           string
	Labels         map[string]string
}

program, err := expr.Compile(target, expr.Env(Instance{}), expr.AsBool())
.......

I can now evaluate the following expression Name == "foobar" but not name == "foobar" since Name is an exported field and thus starts with a capital letter. What would be the best practice here to be able to use lowercase/case insensitive field names in the expressions? Thanks

dpogorzelski avatar Dec 16 '21 22:12 dpogorzelski

What about adding expr.Option for case insensitive vars and names?

expr.CaseInsensitive()

antonmedv avatar Dec 16 '21 22:12 antonmedv

That would be handy :)

dpogorzelski avatar Dec 16 '21 23:12 dpogorzelski

PR are welcome ;)

antonmedv avatar Dec 16 '21 23:12 antonmedv

Haha yep, i'm gonna look into it :)

dpogorzelski avatar Dec 16 '21 23:12 dpogorzelski

Now Expr has expr:"name" tags!

antonmedv avatar Nov 05 '22 19:11 antonmedv