confer
confer copied to clipboard
Add support for configuration subsets
Sometimes there may be a need for passing around subsets of a configuration to your methods. Accessing this section of a config can become very verbose and also a hassle, especially with deeply nested configs. This code change introduces the concept of "configuration subsets", hopefully making it easier to deal with. Please let me know what you think. I am successfully using this with my application, and I'm hoping it may be of benefit to others.
Configuration Subsets
An alternative to the GetStringMap / Materialized paths is a configuration subset. This allows you to create a new *confer.Config object which is a subset of the full configuration, specified by a key prefix. This makes passing around a subset of the configuration easy, allowing you to access the values using the getter methods listed above as you would normally. The setter methods are also supported on a configuration subset, as well as nested configuration subsets.
Example Config
---
my-app:
logging:
enabled: true
level: debug
server:
workers:
- 127.0.0.1
- 127.0.0.2
- 127.0.0.3
database:
bird:
host: feathers
user: postgres
password: superl33+
wind:
host: sea-spray
user: postgres
password: easyPZ
Config Subset
windDbConfig := config.NewConfigSubset("my-app.database.wind")
host := windDbConfig.GetString("host")
Nested Config Subset
dbConfig := config.NewConfigSubset("my-app.database")
windDbConfig := dbConfig.NewConfigSubset("wind")
host := windDbConfig.GetString("host")
Looks like there are issues with godep using tip right now:
https://github.com/tools/godep/issues/452 https://github.com/tools/godep/issues/453
Until that issue is solved, build using tip is not going to succeed on Travis CI.
Cool. I'm curious what the use case here is? How are you using subsets?
Subsets are used like in the example listed above. However in practice, the subset is nested much deeper.
Hi @jacobstr is this something you'd be interested in?