aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/stretchr/objx
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/stretchr/objx')
-rw-r--r--vendor/github.com/stretchr/objx/.travis.yml30
-rw-r--r--vendor/github.com/stretchr/objx/accessors.go36
-rw-r--r--vendor/github.com/stretchr/objx/go.mod2
-rw-r--r--vendor/github.com/stretchr/objx/go.sum8
-rw-r--r--vendor/github.com/stretchr/objx/map.go57
-rw-r--r--vendor/github.com/stretchr/objx/type_specific_codegen.go10
6 files changed, 66 insertions, 77 deletions
diff --git a/vendor/github.com/stretchr/objx/.travis.yml b/vendor/github.com/stretchr/objx/.travis.yml
deleted file mode 100644
index cde6eb2af..000000000
--- a/vendor/github.com/stretchr/objx/.travis.yml
+++ /dev/null
@@ -1,30 +0,0 @@
-language: go
-go:
- - "1.10.x"
- - "1.11.x"
- - "1.12.x"
- - master
-
-matrix:
- allow_failures:
- - go: master
-fast_finish: true
-
-env:
- global:
- - CC_TEST_REPORTER_ID=68feaa3410049ce73e145287acbcdacc525087a30627f96f04e579e75bd71c00
-
-before_script:
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- - chmod +x ./cc-test-reporter
- - ./cc-test-reporter before-build
-
-install:
- - curl -sL https://taskfile.dev/install.sh | sh
-
-script:
- - diff -u <(echo -n) <(./bin/task lint)
- - ./bin/task test-coverage
-
-after_script:
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
diff --git a/vendor/github.com/stretchr/objx/accessors.go b/vendor/github.com/stretchr/objx/accessors.go
index 80ad16740..4c6045588 100644
--- a/vendor/github.com/stretchr/objx/accessors.go
+++ b/vendor/github.com/stretchr/objx/accessors.go
@@ -116,9 +116,15 @@ func getKey(s string) (string, string) {
func access(current interface{}, selector string, value interface{}, isSet bool) interface{} {
thisSel, nextSel := getKey(selector)
- index := -1
- if strings.Contains(thisSel, "[") {
+ indexes := []int{}
+ for strings.Contains(thisSel, "[") {
+ prevSel := thisSel
+ index := -1
index, thisSel = getIndex(thisSel)
+ indexes = append(indexes, index)
+ if prevSel == thisSel {
+ break
+ }
}
if curMap, ok := current.(Map); ok {
@@ -134,7 +140,11 @@ func access(current interface{}, selector string, value interface{}, isSet bool)
}
_, ok := curMSI[thisSel].(map[string]interface{})
- if (curMSI[thisSel] == nil || !ok) && index == -1 && isSet {
+ if !ok {
+ _, ok = curMSI[thisSel].(Map)
+ }
+
+ if (curMSI[thisSel] == nil || !ok) && len(indexes) == 0 && isSet {
curMSI[thisSel] = map[string]interface{}{}
}
@@ -144,15 +154,23 @@ func access(current interface{}, selector string, value interface{}, isSet bool)
}
// do we need to access the item of an array?
- if index > -1 {
- if array, ok := interSlice(current); ok {
- if index < len(array) {
- current = array[index]
- } else {
- current = nil
+ if len(indexes) > 0 {
+ num := len(indexes)
+ for num > 0 {
+ num--
+ index := indexes[num]
+ indexes = indexes[:num]
+ if array, ok := interSlice(current); ok {
+ if index < len(array) {
+ current = array[index]
+ } else {
+ current = nil
+ break
+ }
}
}
}
+
if nextSel != "" {
current = access(current, nextSel, value, isSet)
}
diff --git a/vendor/github.com/stretchr/objx/go.mod b/vendor/github.com/stretchr/objx/go.mod
index 31ec5a7d9..45a55d27e 100644
--- a/vendor/github.com/stretchr/objx/go.mod
+++ b/vendor/github.com/stretchr/objx/go.mod
@@ -4,5 +4,5 @@ go 1.12
require (
github.com/davecgh/go-spew v1.1.1 // indirect
- github.com/stretchr/testify v1.3.0
+ github.com/stretchr/testify v1.7.1
)
diff --git a/vendor/github.com/stretchr/objx/go.sum b/vendor/github.com/stretchr/objx/go.sum
index 4f8984150..c731dbcc8 100644
--- a/vendor/github.com/stretchr/objx/go.sum
+++ b/vendor/github.com/stretchr/objx/go.sum
@@ -4,5 +4,9 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
-github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
+github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/vendor/github.com/stretchr/objx/map.go b/vendor/github.com/stretchr/objx/map.go
index 95149c06a..a64712a08 100644
--- a/vendor/github.com/stretchr/objx/map.go
+++ b/vendor/github.com/stretchr/objx/map.go
@@ -92,6 +92,18 @@ func MustFromJSON(jsonString string) Map {
return o
}
+// MustFromJSONSlice creates a new slice of Map containing the data specified in the
+// jsonString. Works with jsons with a top level array
+//
+// Panics if the JSON is invalid.
+func MustFromJSONSlice(jsonString string) []Map {
+ slice, err := FromJSONSlice(jsonString)
+ if err != nil {
+ panic("objx: MustFromJSONSlice failed with error: " + err.Error())
+ }
+ return slice
+}
+
// FromJSON creates a new Map containing the data specified in the
// jsonString.
//
@@ -102,45 +114,20 @@ func FromJSON(jsonString string) (Map, error) {
if err != nil {
return Nil, err
}
- 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{}))
- }
+// FromJSONSlice creates a new slice of Map containing the data specified in the
+// jsonString. Works with jsons with a top level array
+//
+// Returns an error if the JSON is invalid.
+func FromJSONSlice(jsonString string) ([]Map, error) {
+ var slice []Map
+ err := json.Unmarshal([]byte(jsonString), &slice)
+ if err != nil {
+ return nil, err
}
- return s
+ return slice, nil
}
// FromBase64 creates a new Obj containing the data specified
diff --git a/vendor/github.com/stretchr/objx/type_specific_codegen.go b/vendor/github.com/stretchr/objx/type_specific_codegen.go
index 9859b407f..45850456e 100644
--- a/vendor/github.com/stretchr/objx/type_specific_codegen.go
+++ b/vendor/github.com/stretchr/objx/type_specific_codegen.go
@@ -385,6 +385,11 @@ func (v *Value) Int(optionalDefault ...int) int {
if s, ok := v.data.(int); ok {
return s
}
+ if s, ok := v.data.(float64); ok {
+ if float64(int(s)) == s {
+ return int(s)
+ }
+ }
if len(optionalDefault) == 1 {
return optionalDefault[0]
}
@@ -395,6 +400,11 @@ func (v *Value) Int(optionalDefault ...int) int {
//
// Panics if the object is not a int.
func (v *Value) MustInt() int {
+ if s, ok := v.data.(float64); ok {
+ if float64(int(s)) == s {
+ return int(s)
+ }
+ }
return v.data.(int)
}