- 
                Notifications
    
You must be signed in to change notification settings  - Fork 53
 
Open
Description
In extensible/modular application, it's not possible to create statically defined struct with configuration. And, modular configuration would have for example following configuration:
# syntax: <module_key>.<options...>
module1.option1 = "..."
module1.option2.a = "..."
module1.option2.b = "..."
module1.option3.m = "..."
module1.option3.n = "..."
module1.option3.o = "..."
module2.option1.x = "..."
module2.option1.y = "..."
module2.option1.z = "..."
module2.option2 = "..."
# ...So:
type Module interface {
    LoadConfig(s konfig.Store)
}
type ModuleX struct {}
func (m *ModuleX) LoadConfig(s konfig.Store) {
    var options ModuleXOptions
    s.Unmarshal(&options)
}
func main() {
    var modules map[string]Module = ...
    var config konfig.Store =  ...
    for key, module := range modules {
        // actually, don't know if this works in konfig,... 
        // get all options with prefix `<key>.`
        module.LoadConfig(config.Group(key))
    } 
}Somewhat similar functionality is provided by https://github.com/knadh/koanf#unmarshalling. But, it would need a bit different Module interface:
type Module interface {
    LoadConfig(path string, k *koanf.Koanf)
}
type ModuleX struct {}
func (m *ModuleX) LoadConfig(path string, k *koanf.Koanf) {
    var options ModuleXOptions
    k.Unmarshal(path, &options)
}
func main() {
    ....
}Are there any plans for such/similar support?
Metadata
Metadata
Assignees
Labels
No labels