knadh / koanf

Simple, extremely lightweight, extensible, configuration management library for Go. Support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Thoughts on adding a `.Set(k, v)` method?

hoshsadiq opened this issue · comments

commented

Viper has a Set(key string, value interface{}) method, which allows for easy updating values.

Koanf does not, thus leading to code like this all over the place:

_ = k.Load(confmap.Provider(map[string]interface{}{key: value}, "."), nil)

It would be nice to be able to set individual values so that we can simply do:

k.Set(key, value)

I'd be happy to raise PR if you're okay with it.

commented

I just noticed #144. I don't think Merge() is a good alternative either. This would cause the following code all over the place instead:

k2 := koanf.New(".")
_ = k2.Load(confmap.Provider(map[string]interface{}{key: value}, "."), nil)

k.Merge(k2)

Can you give this a try? #192

commented

Works great! Thanks!