Add in MustBindEnv.

Adds in a MustBindEnv function which will panic if BindEnv fails.
This commit is contained in:
Michael Wilson 2022-02-28 10:03:17 -05:00 committed by Márk Sági-Kazár
parent 3b836e5088
commit f50ce904a9
1 changed files with 11 additions and 0 deletions

View File

@ -1197,6 +1197,17 @@ func (v *Viper) BindEnv(input ...string) error {
return nil return nil
} }
// MustBindEnv wraps BindEnv in a panic.
// If there is an error binding an environment variable, MustBindEnv will
// panic.
func MustBindEnv(input ...string) { v.MustBindEnv(input...) }
func (v *Viper) MustBindEnv(input ...string) {
if err := v.BindEnv(input...); err != nil {
panic(fmt.Sprintf("error while binding environment variable: %v", err))
}
}
// Given a key, find the value. // Given a key, find the value.
// //
// Viper will check to see if an alias exists first. // Viper will check to see if an alias exists first.