Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions enviper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"strings"

"github.com/mitchellh/mapstructure"
"github.com/go-viper/mapstructure/v2"

"github.com/spf13/viper"
)
Expand Down Expand Up @@ -75,7 +75,8 @@ func (e *Enviper) bindEnvs(in interface{}, prev ...string) {
ifv = ifv.Elem()
}

switch ifv.Kind() {
fieldKind := ifv.Kind()
switch fieldKind {
case reflect.Struct:
for i := 0; i < ifv.NumField(); i++ {
fv := ifv.Field(i)
Expand Down Expand Up @@ -120,9 +121,13 @@ func (e *Enviper) bindEnvs(in interface{}, prev ...string) {
}
}
default:
env := strings.Join(prev, ".")
key := strings.Join(prev, ".")
// Viper.BindEnv will never return error
// because env is always non empty string
_ = e.Viper.BindEnv(env)
// because key is always non empty string
if fieldKind != reflect.Slice {
_ = e.Viper.BindEnv(key)
} else {
_ = e.Viper.BindEnvSliceValue(key)
}
}
}