-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add support for configuration subsets #11
base: master
Are you sure you want to change the base?
Conversation
913c1b2
to
f908b35
Compare
Looks like there are issues with tools/godep#452 Until that issue is solved, build using |
// NewConfigSubset returns a new config based on | ||
func (manager *Config) NewConfigSubset(prefix string) *Config { | ||
configSubset := &Config{} | ||
*configSubset = *manager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. You're choosing to copy the data here rather than maintaining a reference. Would it surprise you to find that your subset was unchanged after modifying a value in the parent config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No surprise to me :-).This was intentional, as I only want to modify the subset of config passed. That's why I chose to prefix the function name with "new". I can change it to a reference, but the intent was to make a copy of the subset.
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? |
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 keyprefix
. 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
Config Subset
Nested Config Subset