spf13 / viper

Go configuration with fangs
MIT License
27.19k stars 2.02k forks source link

Environment variable support for config files. #226

Open apremalal opened 8 years ago

apremalal commented 8 years ago

In configuration files we might need to add place holders to ${server_home} kind of variables. Following is a sample yaml file.

serverConfigs:
 prefix : 'CORE_'
 isMaster : true
 portOffset : 0
 httpPort : 8080
 httpsPort : 8085
 adminPort : 9463
 caddyPort : 8082
 readTimeOut : 20
 writeTimeOut : 20
 certificateFile : '{{.ServerHome}}/resources/security/server.pem'
 keyFile : '{{.ServerHome}}/resources/security/server.key'
 JWTPrivateKeyFile : '{{.ServerHome}}/resources/security/private.key'
 JWTPublicKeyFile : '{{.ServerHome}}/resources/security/public.key'

I'm trying to build this as below.

  1. read the original configuration and use template/text support to create a new configuration file after adding the variable values.
  2. Pass the newly constructed file to viper

Can viper does this kind of variable templating out of the box?. if not isn't it worth adding that support?

chen56 commented 6 years ago

why not?

optimistic9527 commented 4 years ago

need support