aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/stretchr/objx/map.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-09-15 18:05:35 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-09-15 19:34:30 +0200
commit712de1c63d9db97c81af68cd0dc4372c53d2e57a (patch)
treeae1761fec52c3ae4ddd003a4130ddbda8d0a2d69 /vendor/github.com/stretchr/objx/map.go
parent298a69c38dd5c8a9bbd7a022e88f4ddbcf885e16 (diff)
vendor/github.com/golangci/golangci-lint: update to v1.31
Diffstat (limited to 'vendor/github.com/stretchr/objx/map.go')
-rw-r--r--vendor/github.com/stretchr/objx/map.go44
1 files changed, 41 insertions, 3 deletions
diff --git a/vendor/github.com/stretchr/objx/map.go b/vendor/github.com/stretchr/objx/map.go
index 406bc8926..95149c06a 100644
--- a/vendor/github.com/stretchr/objx/map.go
+++ b/vendor/github.com/stretchr/objx/map.go
@@ -97,12 +97,50 @@ func MustFromJSON(jsonString string) Map {
//
// Returns an error if the JSON is invalid.
func FromJSON(jsonString string) (Map, error) {
- var data interface{}
- err := json.Unmarshal([]byte(jsonString), &data)
+ var m Map
+ err := json.Unmarshal([]byte(jsonString), &m)
if err != nil {
return Nil, err
}
- return New(data), nil
+ m.tryConvertFloat64()
+ return m, nil
+}
+
+func (m Map) tryConvertFloat64() {
+ for k, v := range m {
+ switch v.(type) {
+ case float64:
+ f := v.(float64)
+ if float64(int(f)) == f {
+ m[k] = int(f)
+ }
+ case map[string]interface{}:
+ t := New(v)
+ t.tryConvertFloat64()
+ m[k] = t
+ case []interface{}:
+ m[k] = tryConvertFloat64InSlice(v.([]interface{}))
+ }
+ }
+}
+
+func tryConvertFloat64InSlice(s []interface{}) []interface{} {
+ for k, v := range s {
+ switch v.(type) {
+ case float64:
+ f := v.(float64)
+ if float64(int(f)) == f {
+ s[k] = int(f)
+ }
+ case map[string]interface{}:
+ t := New(v)
+ t.tryConvertFloat64()
+ s[k] = t
+ case []interface{}:
+ s[k] = tryConvertFloat64InSlice(v.([]interface{}))
+ }
+ }
+ return s
}
// FromBase64 creates a new Obj containing the data specified