Add support for custom struct tags via environment variable#829
Add support for custom struct tags via environment variable#829NickYadance wants to merge 1 commit intoexpr-lang:masterfrom
Conversation
|
@antonmedv how do you think about setting custom gotag from system env ? |
| ) | ||
|
|
||
| func GetGoTag() string { | ||
| if v := os.Getenv(ExprEnvGotag); v != "" { |
There was a problem hiding this comment.
Why do we need to specify this from env?)
There was a problem hiding this comment.
I tried to set gotag in config like expr.Compile("", expr.WithGotag("json")), but there is some expr usage that cannot reach the config value, like in lib.go. Even in where we can reach the config value, it feels code intrusive to pass the value all the way down there. So i picked env since it is easy to read.
Lines 420 to 432 in 1c09e5e
| value := v.FieldByNameFunc(func(name string) bool { | ||
| field, _ := v.Type().FieldByName(name) | ||
| switch field.Tag.Get("expr") { | ||
| switch field.Tag.Get(environment.GetGoTag()) { |
There was a problem hiding this comment.
Better not introduce another configuration surface and use same conf pgk.
| ) | ||
|
|
||
| func GetGoTag() string { | ||
| if v := os.Getenv(ExprEnvGotag); v != "" { |
There was a problem hiding this comment.
We definitely do now want to check os env in expr)
There was a problem hiding this comment.
okay, i'll try some other solutions, closing this now.
Fix: #234
Add support for custom struct tags via environment variable, set gotags to read by system env variables.
To easily reference field by custom go tags like
json,mapstructre, which is especially useful when dealing with generated go structs like protobuf.