Skip to content

Commit

Permalink
fix TestLoadExpandedPortFormat
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Oct 11, 2023
1 parent 839c095 commit 54baead
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions loader/mapstructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package loader

import "reflect"
import (
"reflect"
"strconv"
)

// comparable to yaml.Unmarshaler, decoder allow a type to define it's own custom logic to convert value
// see https://github.com/mitchellh/mapstructure/pull/294
Expand Down Expand Up @@ -53,7 +56,8 @@ func decoderHook(from reflect.Value, to reflect.Value) (interface{}, error) {
}

func cast(from reflect.Value, to reflect.Value) (interface{}, error) {
if from.Type().Kind() == reflect.String {
switch from.Type().Kind() {
case reflect.String:
switch to.Kind() {
case reflect.Bool:
return toBoolean(from.String())
Expand All @@ -66,6 +70,11 @@ func cast(from reflect.Value, to reflect.Value) (interface{}, error) {
case reflect.Float64:
return toFloat(from.String())
}
case reflect.Int:
switch to.Kind() {
case reflect.String:
return strconv.FormatInt(from.Int(), 10), nil
}
}
return from.Interface(), nil
}

0 comments on commit 54baead

Please sign in to comment.