Venom provides helper functions to use the cobra and viper libraries in cunjunction to load application configuration from:
- command-line flags (
cobra
), - environment variables (
viper
), - configuration file(s) (
viper
).
See CHANGELOG.
An example Cobra application can be found under example/main.go.
This example demonstrates how Venom can be used to load configuration variables:
$ go run ./example
Your favorite color is: red
The magic number is: 7
$ go run ./example -n 12
Your favorite color is: red
The magic number is: 12
$ VENOMOUS_FAVORITE_COLOR=purple go run ./example
Your favorite color is: purple
The magic number is: 7
These helpers have been adapted from the article Sting of the Viper: Getting Cobra and Viper to work together by Carolyn Van Slyck, and the corresponding repository, carolynvs/stingoftheviper so they can be used as a library.
The original article demonstrates how to integrate spf13/cobra
with spf13/viper
such that:
- command-line flags have the highest precedence,
- then environment variables,
- then config file values,
- and then defaults set on command-line flags.
Venom is licensed under the MIT license.