Is it possible to load config to the slice of structs?
renom opened this issue · comments
Nikita Boldasov commented
For example:
// Structure to unmarshal nested conf to.
type childStruct struct {
Name string `koanf:"name"`
Type string `koanf:"type"`
Empty map[string]string `koanf:"empty"`
GrandChild []struct {
Ids []int `koanf:"ids"`
On bool `koanf:"on"`
} `koanf:"grandchild1"`
}
How to populate the fields in GrandChild
?
Kailash Nadh commented
Unmarshalling the following JSON for example should work.
{
"name": "xxx",
"grandchild1": [{
"ids": [1, 2, 3, 4],
"on": true
}, {
"ids": [5, 6],
"on": false
}]
}
Nikita Boldasov commented
What about env variables?
Kailash Nadh commented
Please refer to the examples
folder. A slice of structs directly from env, that's not possible out of the box. You will have to do a lot of string manipulation and populate the struct with post-processing.
Nikita Boldasov commented
Thanks!