Skip to content

Commit f50ce90

Browse files
mdwnsagikazarmark
authored andcommitted
Add in MustBindEnv.
Adds in a MustBindEnv function which will panic if BindEnv fails.
1 parent 3b836e5 commit f50ce90

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

viper.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,17 @@ func (v *Viper) BindEnv(input ...string) error {
11971197
return nil
11981198
}
11991199

1200+
// MustBindEnv wraps BindEnv in a panic.
1201+
// If there is an error binding an environment variable, MustBindEnv will
1202+
// panic.
1203+
func MustBindEnv(input ...string) { v.MustBindEnv(input...) }
1204+
1205+
func (v *Viper) MustBindEnv(input ...string) {
1206+
if err := v.BindEnv(input...); err != nil {
1207+
panic(fmt.Sprintf("error while binding environment variable: %v", err))
1208+
}
1209+
}
1210+
12001211
// Given a key, find the value.
12011212
//
12021213
// Viper will check to see if an alias exists first.

0 commit comments

Comments
 (0)