Documentation ¶
Index ¶
- Variables
- func AddWatcher(f func(event fsnotify.Event) error)
- func BindEnvsToSchema(schema json.RawMessage) error
- func GetBool(key string, fallback bool, deprecated ...string) bool
- func GetDuration(key string, fallback time.Duration, deprecated ...string) time.Duration
- func GetFloat64(key string, fallback float64, deprecated ...string) float64
- func GetInt(key string, fallback int, deprecated ...string) int
- func GetString(key string, fallback string, deprecated ...string) string
- func GetStringMapConfig(paths ...string) map[string]interface{}
- func GetStringSlice(key string, fallback []string, deprecated ...string) []string
- func InitializeConfig(applicationName string, homeOverride string)
- func PrintHumanReadableValidationErrors(w io.Writer, err error)
- func RegisterConfigFlag(c *cobra.Command, applicationName string)
- func ResetWatchers()
- func UnmarshalKey(key string, destination interface{}) error
- func Validate(name string, content []byte) error
- func ValidateFromURL(url string) error
- func WatchAndValidateViper(schema []byte, productName string, immutables []string, ...)
- func WatchConfig(o *WatchOptions)
- type WatchOptions
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 GetDuration ¶
GetDuration returns a duration from viper config or the fallback value.
func GetFloat64 ¶
GetFloat64 returns a float64 value from viper config or the fallback value.
func GetStringMapConfig ¶
GetStringMapConfig returns a string map using all settings which will lookup env vars
func GetStringSlice ¶
GetStringSlice returns a string slice from viper config or the fallback value.
func InitializeConfig ¶
InitializeConfig initializes viper.
func PrintHumanReadableValidationErrors ¶
PrintHumanReadableValidationErrors prints human readable validation errors. Duh.
func RegisterConfigFlag ¶
RegisterConfigFlag registers the --config / -c flag.
func UnmarshalKey ¶
UnmarshalKey unmarshals a viper key into the destination struct. The destination struct must be JSON-compatible (i.e. have `json` struct tags)
func Validate ¶
Validate validates the viper config
If env vars are supported, they must be bound using viper.BindEnv.
func ValidateFromURL ¶
ValidateFromURL validates the viper config by loading the schema from a URL
Uses Validate internally.
func WatchAndValidateViper ¶
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.