venom

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 6 Imported by: 2

README

venom - Configuration management helper for cobra and viper 🐍

Continuous Integration workflow status

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).

Change Log

See CHANGELOG.

Example

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

Credits

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.

License

Venom is licensed under the MIT license.

Documentation

Overview

Package 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) and configuration file(s) (viper).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inject

func Inject(cmd *cobra.Command, envPrefix string, configPaths []string, configName string, replaceHyphenWithCamelCase bool) error

Inject creates a new viper.Viper and binds environment variables and configuration file settings to command flags.

func InjectTo added in v1.1.0

func InjectTo(v *viper.Viper, cmd *cobra.Command, envPrefix string, configPaths []string, configName string, replaceHyphenWithCamelCase bool) error

Inject binds environment variables and configuration file settings to command flags using an existing viper.Viper.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL