Skip to content

Commit

Permalink
Add in MustBindEnv.
Browse files Browse the repository at this point in the history
Adds in a MustBindEnv function which will panic if BindEnv fails.
  • Loading branch information
mdwn authored and sagikazarmark committed May 26, 2022
1 parent 3b836e5 commit f50ce90
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions viper.go
Expand Up @@ -1197,6 +1197,17 @@ func (v *Viper) BindEnv(input ...string) error {
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.
//
// Viper will check to see if an alias exists first.
Expand Down

0 comments on commit f50ce90

Please sign in to comment.