Viper – easy configuration for CLIs
Steve Francia, author of Cobra, also created a configuration tool, Viper, to easily integrate with Cobra. For a simple application that you’re running locally on your machine, you may not initially need a configuration tool. However, if your application may run within different environments that require different integrations, API keys, or general customizations that are better in a config file versus hardcoded, Viper will help ease the process of configuring your app.
Configuration types
There are many ways Viper allows you to set your application’s configuration:
- Reading from configuration files
- With environment variables
- With remote config systems
- With command-line flags
- With a buffer
The configuration formats accepted from these configuration types include JSON, TOML, YAML, HCL, INI, envfile, and Java properties formats. To get a better understanding, let’s go over an example of...