Thoughts on adding a `.Set(k, v)` method?
hoshsadiq opened this issue · comments
Hosh 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.
Hosh 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)
Kailash Nadh commented
Can you give this a try? #192
Hosh commented
Works great! Thanks!