From baf7141d1dd0f99d561a2197a909c66dd389809d Mon Sep 17 00:00:00 2001 From: Niall Sheridan Date: Sat, 8 Oct 2016 16:02:50 -0500 Subject: Update dependencies --- vendor/github.com/spf13/cast/caste.go | 70 ++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 22 deletions(-) (limited to 'vendor/github.com/spf13/cast/caste.go') diff --git a/vendor/github.com/spf13/cast/caste.go b/vendor/github.com/spf13/cast/caste.go index 863585b..23f59a1 100644 --- a/vendor/github.com/spf13/cast/caste.go +++ b/vendor/github.com/spf13/cast/caste.go @@ -12,14 +12,11 @@ import ( "strconv" "strings" "time" - - jww "github.com/spf13/jwalterweatherman" ) // ToTimeE casts an empty interface to time.Time. func ToTimeE(i interface{}) (tim time.Time, err error) { i = indirect(i) - jww.TRACE.Println("ToTimeE called on type:", reflect.TypeOf(i)) switch s := i.(type) { case time.Time: @@ -38,19 +35,22 @@ func ToTimeE(i interface{}) (tim time.Time, err error) { // ToDurationE casts an empty interface to time.Duration. func ToDurationE(i interface{}) (d time.Duration, err error) { i = indirect(i) - jww.TRACE.Println("ToDurationE called on type:", reflect.TypeOf(i)) switch s := i.(type) { case time.Duration: return s, nil - case int64: - d = time.Duration(s) + case int64, int32, int16, int8, int: + d = time.Duration(ToInt64(s)) return - case float64: - d = time.Duration(s) + case float32, float64: + d = time.Duration(ToFloat64(s)) return case string: - d, err = time.ParseDuration(s) + if strings.ContainsAny(s, "nsuµmh") { + d, err = time.ParseDuration(s) + } else { + d, err = time.ParseDuration(s + "ns") + } return default: err = fmt.Errorf("Unable to Cast %#v to Duration\n", i) @@ -60,8 +60,8 @@ func ToDurationE(i interface{}) (d time.Duration, err error) { // ToBoolE casts an empty interface to a bool. func ToBoolE(i interface{}) (bool, error) { + i = indirect(i) - jww.TRACE.Println("ToBoolE called on type:", reflect.TypeOf(i)) switch b := i.(type) { case bool: @@ -83,7 +83,6 @@ func ToBoolE(i interface{}) (bool, error) { // ToFloat64E casts an empty interface to a float64. func ToFloat64E(i interface{}) (float64, error) { i = indirect(i) - jww.TRACE.Println("ToFloat64E called on type:", reflect.TypeOf(i)) switch s := i.(type) { case float64: @@ -114,7 +113,6 @@ func ToFloat64E(i interface{}) (float64, error) { // ToInt64E casts an empty interface to an int64. func ToInt64E(i interface{}) (int64, error) { i = indirect(i) - jww.TRACE.Println("ToInt64E called on type:", reflect.TypeOf(i)) switch s := i.(type) { case int64: @@ -150,7 +148,6 @@ func ToInt64E(i interface{}) (int64, error) { // ToIntE casts an empty interface to an int. func ToIntE(i interface{}) (int, error) { i = indirect(i) - jww.TRACE.Println("ToIntE called on type:", reflect.TypeOf(i)) switch s := i.(type) { case int: @@ -225,7 +222,6 @@ func indirectToStringerOrError(a interface{}) interface{} { // ToStringE casts an empty interface to a string. func ToStringE(i interface{}) (string, error) { i = indirectToStringerOrError(i) - jww.TRACE.Println("ToStringE called on type:", reflect.TypeOf(i)) switch s := i.(type) { case string: @@ -263,7 +259,6 @@ func ToStringE(i interface{}) (string, error) { // ToStringMapStringE casts an empty interface to a map[string]string. func ToStringMapStringE(i interface{}) (map[string]string, error) { - jww.TRACE.Println("ToStringMapStringE called on type:", reflect.TypeOf(i)) var m = map[string]string{} @@ -292,7 +287,6 @@ func ToStringMapStringE(i interface{}) (map[string]string, error) { // ToStringMapStringSliceE casts an empty interface to a map[string][]string. func ToStringMapStringSliceE(i interface{}) (map[string][]string, error) { - jww.TRACE.Println("ToStringMapStringSliceE called on type:", reflect.TypeOf(i)) var m = map[string][]string{} @@ -310,7 +304,14 @@ func ToStringMapStringSliceE(i interface{}) (map[string][]string, error) { } case map[string]interface{}: for k, val := range v { - m[ToString(k)] = []string{ToString(val)} + switch vt := val.(type) { + case []interface{}: + m[ToString(k)] = ToStringSlice(vt) + case []string: + m[ToString(k)] = vt + default: + m[ToString(k)] = []string{ToString(val)} + } } return m, nil case map[interface{}][]string: @@ -348,7 +349,6 @@ func ToStringMapStringSliceE(i interface{}) (map[string][]string, error) { // ToStringMapBoolE casts an empty interface to a map[string]bool. func ToStringMapBoolE(i interface{}) (map[string]bool, error) { - jww.TRACE.Println("ToStringMapBoolE called on type:", reflect.TypeOf(i)) var m = map[string]bool{} @@ -372,7 +372,6 @@ func ToStringMapBoolE(i interface{}) (map[string]bool, error) { // ToStringMapE casts an empty interface to a map[string]interface{}. func ToStringMapE(i interface{}) (map[string]interface{}, error) { - jww.TRACE.Println("ToStringMapE called on type:", reflect.TypeOf(i)) var m = map[string]interface{}{} @@ -391,7 +390,6 @@ func ToStringMapE(i interface{}) (map[string]interface{}, error) { // ToSliceE casts an empty interface to a []interface{}. func ToSliceE(i interface{}) ([]interface{}, error) { - jww.TRACE.Println("ToSliceE called on type:", reflect.TypeOf(i)) var s []interface{} @@ -411,9 +409,38 @@ func ToSliceE(i interface{}) ([]interface{}, error) { } } +// ToBoolSliceE casts an empty interface to a []bool. +func ToBoolSliceE(i interface{}) ([]bool, error) { + + if i == nil { + return []bool{}, fmt.Errorf("Unable to Cast %#v to []bool", i) + } + + switch v := i.(type) { + case []bool: + return v, nil + } + + kind := reflect.TypeOf(i).Kind() + switch kind { + case reflect.Slice, reflect.Array: + s := reflect.ValueOf(i) + a := make([]bool, s.Len()) + for j := 0; j < s.Len(); j++ { + val, err := ToBoolE(s.Index(j).Interface()) + if err != nil { + return []bool{}, fmt.Errorf("Unable to Cast %#v to []bool", i) + } + a[j] = val + } + return a, nil + default: + return []bool{}, fmt.Errorf("Unable to Cast %#v to []bool", i) + } +} + // ToStringSliceE casts an empty interface to a []string. func ToStringSliceE(i interface{}) ([]string, error) { - jww.TRACE.Println("ToStringSliceE called on type:", reflect.TypeOf(i)) var a []string @@ -440,7 +467,6 @@ func ToStringSliceE(i interface{}) ([]string, error) { // ToIntSliceE casts an empty interface to a []int. func ToIntSliceE(i interface{}) ([]int, error) { - jww.TRACE.Println("ToIntSliceE called on type:", reflect.TypeOf(i)) if i == nil { return []int{}, fmt.Errorf("Unable to Cast %#v to []int", i) -- cgit v1.2.3