Skip to content

Commit

Permalink
refactor: rearrange control flow in method loadField
Browse files Browse the repository at this point in the history
  • Loading branch information
raymond-chia committed Aug 3, 2020
1 parent 28b90dd commit 7d6a7cf
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions envconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,50 +38,47 @@ func (l *loader) useKey(name string) error {
}

func (l *loader) loadField(name string, out *reflect.Value) {
kind := out.Kind()
if kind == reflect.Struct {
l.loadStruct(name, out)
return
}

if err := l.useKey(name); err != nil {
panic(err)
}

switch out.Kind() {
case reflect.String:
if err := l.useKey(name); err != nil {
panic(err)
}
l.loadString(name, out)
return

case reflect.Int,
reflect.Int8,
reflect.Int16,
reflect.Int32,
reflect.Int64:
if err := l.useKey(name); err != nil {
panic(err)
}
l.loadInt(name, out)
return

case reflect.Uint,
reflect.Uint8,
reflect.Uint16,
reflect.Uint32,
reflect.Uint64:
if err := l.useKey(name); err != nil {
panic(err)
}
l.loadUint(name, out)
return

case reflect.Bool:
if err := l.useKey(name); err != nil {
panic(err)
}
l.loadBool(name, out)

case reflect.Struct:
l.loadStruct(name, out)
return

case reflect.Slice:
sliceType := out.Type()
switch sliceType {
case stringSliceType:
if err := l.useKey(name); err != nil {
panic(err)
}
l.loadStringSlice(name, out)
return

default:
panic(fmt.Errorf("slice type %v on %v is not supported", sliceType, name))
Expand Down

0 comments on commit 7d6a7cf

Please sign in to comment.