Pick up configuration file changes
-
c.merge(/* config.yml */) -
c.get("k") - modify config.yml -> k
-
c.get("k")
The second get should reflect the changes to the config file.
I think we get this for free with the DeserializeSeed approach proposed in #13.
This would either require watching the file for changes, or re-reading all config on every get, both of which have performance implications that would not acceptable in every application. I think this would be a great feature, as long as there is still a way to read config just once.
Yeah.. I definitely want this as there are lot of use cases that could benefit. Here is the API in my head:
c.merge(File::with_name("Settings"));
c.get("key"); //= 1
c.watch(|| {
// Do something when your config changes
});
Without calling c.watch, the configuration would not watch FS or listen for write events in Etcd.
This issue made me remember about #20. We should probably get that story down first before tackling automatic refresh.
This is now possible ( check out https://github.com/mehcode/config-rs/blob/master/examples/watch/src/main.rs )
A couple more questions to answer before .watch should be added.
-
Is
Config.watchstating that we are watching all sources? I'd think so. -
Should there be a way to opt-out or opt-in to watching at a per-source level?