-
Notifications
You must be signed in to change notification settings - Fork 385
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
Feature Request: multiple names for fields #163
Comments
How should ordering work? I think the big challenge will be dealing with the ambiguous nature of an env var being unset vs set to empty. |
Couldn't we use the order provided ?
But I would argue that the order should not matter here actually. Users should only set one of these environment variables and envconfig pick the first one that is not nil. |
Not exactly what you asked for but you can work around this by creating two entries and a function to return any non-empty one: type Config struct {
SomethingNew string `envconfig:setting_name`
SomethingOld string `envconfig:deprecated_name`
}
func (cfg *Config) Something() string {
if cfg.SomethingNew != "" {
return cfg.SomethingNew
}
return cfg.SomethingOld
} |
Maybe the ordering is not that important. You won't likely see both being set explicitly, since you either specify the deprecated key name because you haven't migrated yet or migrated to the new key and won't be setting the old anymore. In that case it could be a either or setting that guards this but you should not specify both? EDIT: maybe something like this: type Config struct {
SomeSetting string `envconfig:"setting_name" alternative:"deprecated_name"`
} or type Config struct {
SomeSetting string `envconfig:"setting_name" deprecated:"deprecated_name"`
} In the second example it could even be possible to add a way to handle the usage of deprecated keys (e.g. logging?) |
I'd like to be able to specify multiple/alternate names for a config field. I'm envisioning a rough equivalent to the EnvVars setting in urfave/cli:
Right now, we're working around it with multiple structs:
The text was updated successfully, but these errors were encountered: