-
Notifications
You must be signed in to change notification settings - Fork 2k
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
env var substitution inside config file #418
Comments
I'm looking for a similar solution. My current application has config files that look like this:
and I would like to continue to use these configuration files as-is with the |
This will help me to improve an application. I need some way to set the base URL for n HTTP consumers: consumer-name-1:
connection: default
queue:
name: "wololo"
options:
durable: true
runner:
type: http
options:
url: https://myurl/app/message/wololo-handler"
consumer-name-2:
connection: default
queue:
name: "fooo"
options:
durable: true
runner:
type: http
options:
url: https://myurl/app/message/fooo-handler" I can help if needed! |
try godotenv |
Why not support this feature? |
There are better ways for this that doesn't require a direct integration in Viper:
Personally, I think if you use env vars anyway, it's just better to load them using Viper instead of replacing values in a config file. Since there are alternatives available, I'm going to close this as won't fix. Feel free to open a new issue if you think you have a strong case for implementing this feature. |
This would be super convenient actually. I hope you can reconsider. |
Yes func StringExpandEnv() mapstructure.DecodeHookFuncKind {
return func(
f reflect.Kind,
t reflect.Kind,
data interface{}) (interface{}, error) {
if f != reflect.String || t != reflect.String {
return data, nil
}
return os.ExpandEnv(data.(string)), nil
}
}
err := viper.Unmarshal(&config, viper.DecodeHook(StringExpandEnv())) |
Considering the following example YAML file excerpt:
While reading the config, the value ${DOWNSTREAM_SERVICES_URL} should be replaced with env var value of DOWNSTREAM_SERVICES_URL.
Is there some decoder hook I can use to implement this substitution?
The text was updated successfully, but these errors were encountered: