viper-go

Go viper .yaml values environment variables override

拟墨画扇 提交于 2021-01-27 22:08:55
问题 I'm trying to have application.yaml file in go application which contains ${RMQ_HOST} values which I want to override with environment variables. In application.yaml I've got: rmq: test: host: ${RMQ_HOST} port: ${RMQ_PORT} And in my loader I have: log.Println("Loading config...") viper.SetConfigName("application") viper.SetConfigType("yaml") viper.AddConfigPath(".") viper.AutomaticEnv() err := viper.ReadInConfig() The problem I have is ${RMQ_HOST} won't get replaced by the values I've set in

How Do I Unmarshal Dynamic Viper or JSON keys as part of struct field in go

做~自己de王妃 提交于 2019-12-31 07:08:03
问题 I find the marshaling & unMarshaling in GOLANG very confusing when JSON is not in "desired" format. For example, in a JSON config file (which I am trying to use with Viper) I have a config file that looks like : { "things" :{ "123abc" :{ "key1": "anything", "key2" : "more" }, "456xyz" :{ "key1": "anything2", "key2" : "more2" }, "blah" :{ "key1": "anything3", "key2" : "more3" } } } where "things" could be an object in another object n levels down and I have a struct : type Thing struct { Name

Share properties from separate commands/process

ぐ巨炮叔叔 提交于 2019-12-22 08:23:55
问题 Im providing command line tool with several command and sub commands, Im using cobra command line and I’ve two separate commands that first is prerequisit e to other e.g. the first command is preferring the environment by creating temp folder and validate some file The second command should get some properties from the first command and user should execute it like btr prepare btr run when the run command is executed it should get some data from the prepare command outcome // rootCmd

Cobra + Viper Golang How to test subcommands?

二次信任 提交于 2019-12-21 07:58:06
问题 I am developing an web app with Go. So far so good, but now I am integrating Wercker as a CI tool and started caring about testing. But my app relies heavily on Cobra/Viper configuration/flags/environment_variables scheme, and I do not know how to properly init Viper values before running my test suite. Any help would be much appreciated. 回答1: When I use Cobra/Viper or any other combination of CLI helpers, my way of doing this is to have the CLI tool run a function whose sole purpose will be

Share properties from separate commands/process

折月煮酒 提交于 2019-12-05 12:43:34
Im providing command line tool with several command and sub commands, Im using cobra command line and I’ve two separate commands that first is prerequisit e to other e.g. the first command is preferring the environment by creating temp folder and validate some file The second command should get some properties from the first command and user should execute it like btr prepare btr run when the run command is executed it should get some data from the prepare command outcome // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "btr", Short:

Cobra + Viper Golang How to test subcommands?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 02:08:44
I am developing an web app with Go. So far so good, but now I am integrating Wercker as a CI tool and started caring about testing. But my app relies heavily on Cobra/Viper configuration/flags/environment_variables scheme, and I do not know how to properly init Viper values before running my test suite. Any help would be much appreciated. When I use Cobra/Viper or any other combination of CLI helpers, my way of doing this is to have the CLI tool run a function whose sole purpose will be to get arguments and pass them to another method who will do the actual work. Here is a short (and dumb)