Skip to content

Commit

Permalink
Add a way to pass viper.DecoderConfigOption to Unmarshal()
Browse files Browse the repository at this point in the history
  • Loading branch information
leventov authored and iamolegga committed Mar 29, 2021
1 parent 2e1108f commit 17ee712
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions enviper.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func New(v *viper.Viper) *Enviper {

// Unmarshal unmarshals the config into a Struct just like viper does.
// The difference between enviper and viper is in automatic overriding data from file by data from env variables
func (e *Enviper) Unmarshal(rawVal interface{}) error {
func (e *Enviper) Unmarshal(rawVal interface{}, opts ...viper.DecoderConfigOption) error {
if err := e.Viper.ReadInConfig(); err != nil {
switch err.(type) {
case viper.ConfigFileNotFoundError:
Expand All @@ -57,9 +57,9 @@ func (e *Enviper) Unmarshal(rawVal interface{}) error {
}
// We need to unmarshal before the env binding to make sure that keys of maps are bound just like the struct fields
// We silence errors here because we'll unmarshal a second time
_ = e.Viper.Unmarshal(rawVal)
_ = e.Viper.Unmarshal(rawVal, opts...)
e.readEnvs(rawVal)
return e.Viper.Unmarshal(rawVal)
return e.Viper.Unmarshal(rawVal, opts...)
}

func (e *Enviper) readEnvs(rawVal interface{}) {
Expand Down

0 comments on commit 17ee712

Please sign in to comment.