Viper or Vipers?

Viper comes ready to use out of the box. There is no configuration orinitialization needed to begin using Viper. Since most applications will wantto use a single central repository for their configuration, the viper packageprovides this. It is similar to a singleton.

In all of the examples above, they demonstrate using viper in its singletonstyle approach.

Working with multiple vipers

You can also create many different vipers for use in your application. Each willhave its own unique set of configurations and values. Each can read from adifferent config file, key value store, etc. All of the functions that viperpackage supports are mirrored as methods on a viper.

Example:

  1. x := viper.New()
  2. y := viper.New()
  3.  
  4. x.SetDefault("ContentDir", "content")
  5. y.SetDefault("ContentDir", "foobar")
  6.  
  7. //...

When working with multiple vipers, it is up to the user to keep track of thedifferent vipers.