summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/stretchr/objx/accessors.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/stretchr/objx/accessors.go')
-rw-r--r--vendor/github.com/stretchr/objx/accessors.go33
1 files changed, 5 insertions, 28 deletions
diff --git a/vendor/github.com/stretchr/objx/accessors.go b/vendor/github.com/stretchr/objx/accessors.go
index d95be0ca9..204356a22 100644
--- a/vendor/github.com/stretchr/objx/accessors.go
+++ b/vendor/github.com/stretchr/objx/accessors.go
@@ -1,7 +1,6 @@
package objx
import (
- "fmt"
"regexp"
"strconv"
"strings"
@@ -28,7 +27,7 @@ var arrayAccesRegex = regexp.MustCompile(arrayAccesRegexString)
//
// o.Get("books[1].chapters[2].title")
func (m Map) Get(selector string) *Value {
- rawObj := access(m, selector, nil, false, false)
+ rawObj := access(m, selector, nil, false)
return &Value{data: rawObj}
}
@@ -43,34 +42,25 @@ func (m Map) Get(selector string) *Value {
//
// o.Set("books[1].chapters[2].title","Time to Go")
func (m Map) Set(selector string, value interface{}) Map {
- access(m, selector, value, true, false)
+ access(m, selector, value, true)
return m
}
// access accesses the object using the selector and performs the
// appropriate action.
-func access(current, selector, value interface{}, isSet, panics bool) interface{} {
-
+func access(current, selector, value interface{}, isSet bool) interface{} {
switch selector.(type) {
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
-
if array, ok := current.([]interface{}); ok {
index := intFromInterface(selector)
-
if index >= len(array) {
- if panics {
- panic(fmt.Sprintf("objx: Index %d is out of range. Slice only contains %d items.", index, len(array)))
- }
return nil
}
-
return array[index]
}
-
return nil
case string:
-
selStr := selector.(string)
selSegs := strings.SplitN(selStr, PathSeparator, 2)
thisSel := selSegs[0]
@@ -79,7 +69,6 @@ func access(current, selector, value interface{}, isSet, panics bool) interface{
if strings.Contains(thisSel, "[") {
arrayMatches := arrayAccesRegex.FindStringSubmatch(thisSel)
-
if len(arrayMatches) > 0 {
// Get the key into the map
thisSel = arrayMatches[1]
@@ -94,11 +83,9 @@ func access(current, selector, value interface{}, isSet, panics bool) interface{
}
}
}
-
if curMap, ok := current.(Map); ok {
current = map[string]interface{}(curMap)
}
-
// get the object in question
switch current.(type) {
case map[string]interface{}:
@@ -111,29 +98,19 @@ func access(current, selector, value interface{}, isSet, panics bool) interface{
default:
current = nil
}
-
- if current == nil && panics {
- panic(fmt.Sprintf("objx: '%v' invalid on object.", selector))
- }
-
// do we need to access the item of an array?
if index > -1 {
if array, ok := current.([]interface{}); ok {
if index < len(array) {
current = array[index]
} else {
- if panics {
- panic(fmt.Sprintf("objx: Index %d is out of range. Slice only contains %d items.", index, len(array)))
- }
current = nil
}
}
}
-
if len(selSegs) > 1 {
- current = access(current, selSegs[1], value, isSet, panics)
+ current = access(current, selSegs[1], value, isSet)
}
-
}
return current
}
@@ -165,7 +142,7 @@ func intFromInterface(selector interface{}) int {
case uint64:
value = int(selector.(uint64))
default:
- panic("objx: array access argument is not an integer type (this should never happen)")
+ return 0
}
return value
}