-
Notifications
You must be signed in to change notification settings - Fork 62
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
user-supplied variable names -- vote for inclusion in v1 #9
base: v1
Are you sure you want to change the base?
Conversation
👍 source: https://github.com/xorpaul/gorpe/blob/master/gorped.go#L253 |
Thanks for the feedback. For the record, yours seems to be the only use in public code on Github: https://github.com/search?q=gcfg.Idxer&type=Code . I think there should be at the very least 3-5 use cases so that we can decide whether the feature is suitable for the wide public. On a side note, I'd suggest not to use Idxer for the |
As I mentioned in #10 , we've been using a more basic approach with similar goals; among other things, we want to support an I'm definitely +1 for the feature, I'm not sure I like the requirement of this implementation to embed gcfg-specific objects into my struct though; I find it nice that the struct doesn't normally have to have any special features for gcfg to parse into it, similar to |
@peterebden Thanks for the feedback again. Note that git alias is also case-insensitive. I know that having to embed gcfg.Indexer is a bit clumsy but (so far) it's the best compromise I've managed to find that allows case-insensitive matching. |
Throwing my vote in on getting this merged into v1. We are currently using this branch in our config library so that we can have both structured and dynamic elements in our configs. Here is our wrapped config library that "does the things": https://godoc.org/github.com/gravwell/ingest/config#VariableConfig So, big up-vote from us, would be really nice to see this merged into the mainline branch. Also, thank you for the library, its great!. |
Vote for this tentative pull request (PR) to be merged into branch
v1
either by using 👍 or by adding a comment describing your use case (and ideally link to source). Other (constructive) feedback is also welcome.Currently (in the
v1
branch) all variable names are supplied by the developer (who implements the configuration struct) as field names (or in field tags). In some situations it is useful to allow the user (who edits the configuration file) to define arbitrary variable names. An example of such usage is the[alias]
section in.gitconfig
.This PR adds support for user-supplied variables. A section can contain either all developer-supplied or all user-supplied variables. With user-supplied variables the variable names are case-insensitive (so it is not as simple as a
map[string]Something
), and the order of variables is not preserved. This is to maintain consistency with developer-supplied variables.A section with user-defined variables is declared as a struct with two members: an embedded
gcfg.Idxer
and amap[gcfg.Idx]*Something
, for example:After using
gcfg.Read*Into
, looking up a variable is done as follows:Iterating through the variables is done as follows (the case and order of names is undefined):