Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for unmarshalling of loaded config #61

Open
kravemir opened this issue Feb 4, 2020 · 0 comments
Open

Support for unmarshalling of loaded config #61

kravemir opened this issue Feb 4, 2020 · 0 comments

Comments

@kravemir
Copy link

kravemir commented Feb 4, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant