Using Viper for Configuration Management
Learn how to use Viper for configuration management in our application.
We'll cover the following
When we use the Cobra generator to create the boilerplate code for our application, it automatically enables Viper. Viper is a configuration management solution for Go applications that allows us to specify configuration options for our application in several ways, including configuration files, environment variables, and command-line flags.
Defining the initConfig()
function
Cobra enables Viper by running the function initConfig()
when initializing the
application. This function is defined in the cmd/root.go
file:
Get hands-on with 1400+ tech skills courses.