aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/spf13/cast/caste.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/cast/caste.go')
-rw-r--r--vendor/github.com/spf13/cast/caste.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/vendor/github.com/spf13/cast/caste.go b/vendor/github.com/spf13/cast/caste.go
index 81511fe..4fe1928 100644
--- a/vendor/github.com/spf13/cast/caste.go
+++ b/vendor/github.com/spf13/cast/caste.go
@@ -6,6 +6,7 @@
package cast
import (
+ "encoding/json"
"errors"
"fmt"
"html/template"
@@ -872,6 +873,9 @@ func ToStringMapStringE(i interface{}) (map[string]string, error) {
m[ToString(k)] = ToString(val)
}
return m, nil
+ case string:
+ err := jsonStringToObject(v, &m)
+ return m, err
default:
return m, fmt.Errorf("unable to cast %#v of type %T to map[string]string", i, i)
}
@@ -932,6 +936,9 @@ func ToStringMapStringSliceE(i interface{}) (map[string][]string, error) {
}
m[key] = value
}
+ case string:
+ err := jsonStringToObject(v, &m)
+ return m, err
default:
return m, fmt.Errorf("unable to cast %#v of type %T to map[string][]string", i, i)
}
@@ -955,6 +962,9 @@ func ToStringMapBoolE(i interface{}) (map[string]bool, error) {
return m, nil
case map[string]bool:
return v, nil
+ case string:
+ err := jsonStringToObject(v, &m)
+ return m, err
default:
return m, fmt.Errorf("unable to cast %#v of type %T to map[string]bool", i, i)
}
@@ -972,6 +982,9 @@ func ToStringMapE(i interface{}) (map[string]interface{}, error) {
return m, nil
case map[string]interface{}:
return v, nil
+ case string:
+ err := jsonStringToObject(v, &m)
+ return m, err
default:
return m, fmt.Errorf("unable to cast %#v of type %T to map[string]interface{}", i, i)
}
@@ -1144,3 +1157,10 @@ func parseDateWith(s string, dates []string) (d time.Time, e error) {
}
return d, fmt.Errorf("unable to parse date: %s", s)
}
+
+// jsonStringToObject attempts to unmarshall a string as JSON into
+// the object passed as pointer.
+func jsonStringToObject(s string, v interface{}) error {
+ data := []byte(s)
+ return json.Unmarshal(data, v)
+}