I'm designing config component where I want to set ENV variable for each field on go struct.
e.g.
type SubStruct struct {
Field int `env:"ENV_INT"`
}
type Config struct {
Name string `env:"APP_NAME"`
Sub1 struct {
Sub11 struct {
Value string `env:"ENV_VAR"`
}
Sub12 SubStruct
}
}
What I want to achieve is to:
- Get values of all
env
keys recursively - Set value based on field type
So there are basically two questions:
Is there any lib in go which exposes methods for setting values using reflection (e.g. like private methods in json package)?
Is there any method/function in go which can parse your struct recursively and get all tags from struct?
edit: - updated structs - renamed confusing field names (from embed to sub)