viper

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRollbackConfigurationChanges = errors.New("an error occurred and configuration changes should be reverted")

ErrRollbackConfigurationChanges should be used when a configuration is e.g. invalid and should be rolled back.

Functions

func AddWatcher

func AddWatcher(f func(event fsnotify.Event) error)

AddWatcher adds a function callback to viper.OnConfigChange().

func BindEnvsToSchema

func BindEnvsToSchema(schema json.RawMessage) error

BindEnvsToSchema uses all keys it can find from “

func GetBool

func GetBool(key string, fallback bool, deprecated ...string) bool

GetBool returns a bool from viper config or false.

func GetDuration

func GetDuration(key string, fallback time.Duration, deprecated ...string) time.Duration

GetDuration returns a duration from viper config or the fallback value.

func GetFloat64

func GetFloat64(key string, fallback float64, deprecated ...string) float64

GetFloat64 returns a float64 value from viper config or the fallback value.

func GetInt

func GetInt(key string, fallback int, deprecated ...string) int

GetInt returns an int value from viper config or the fallback value.

func GetString

func GetString(key string, fallback string, deprecated ...string) string

GetString returns a string from viper config or the fallback value.

func GetStringMapConfig

func GetStringMapConfig(paths ...string) map[string]interface{}

GetStringMapConfig returns a string map using all settings which will lookup env vars

func GetStringSlice

func GetStringSlice(key string, fallback []string, deprecated ...string) []string

GetStringSlice returns a string slice from viper config or the fallback value.

func InitializeConfig

func InitializeConfig(applicationName string, homeOverride string)

InitializeConfig initializes viper.

func PrintHumanReadableValidationErrors

func PrintHumanReadableValidationErrors(w io.Writer, err error)

PrintHumanReadableValidationErrors prints human readable validation errors. Duh.

func RegisterConfigFlag

func RegisterConfigFlag(c *cobra.Command, applicationName string)

RegisterConfigFlag registers the --config / -c flag.

func ResetWatchers

func ResetWatchers()

ResetWatchers resets all the watchers.

func UnmarshalKey

func UnmarshalKey(key string, destination interface{}) error

UnmarshalKey unmarshals a viper key into the destination struct. The destination struct must be JSON-compatible (i.e. have `json` struct tags)

func Validate

func Validate(name string, content []byte) error

Validate validates the viper config

If env vars are supported, they must be bound using viper.BindEnv.

func ValidateFromURL

func ValidateFromURL(url string) error

ValidateFromURL validates the viper config by loading the schema from a URL

Uses Validate internally.

func WatchAndValidateViper

func WatchAndValidateViper(schema []byte, productName string, immutables []string, sensitiveDumpConfigDir string)

func WatchConfig

func WatchConfig(o *WatchOptions)

WatchConfig is a helper makes watching configuration files easy.

Types

type WatchOptions

type WatchOptions struct {
	// Immutables are keys that cause OnImmutableChange to be fired when modified.
	Immutables []string
	// OnImmutableChange - see Immutables.
	OnImmutableChange func(key string)
}

WatchOptions configures WatchConfig.

Jump to

Keyboard shortcuts

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