From 961c04cae992eadb42d286d2f85f8a675bdc68c8 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 29 Jan 2018 14:17:40 -0800 Subject: Upgrading server dependancies (#8154) --- vendor/github.com/stretchr/objx/accessors.go | 43 ++++------------------------ 1 file changed, 6 insertions(+), 37 deletions(-) (limited to 'vendor/github.com/stretchr/objx/accessors.go') diff --git a/vendor/github.com/stretchr/objx/accessors.go b/vendor/github.com/stretchr/objx/accessors.go index 721bcac79..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,47 +42,34 @@ 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] index := -1 var err error - // https://github.com/stretchr/objx/issues/12 if strings.Contains(thisSel, "[") { - arrayMatches := arrayAccesRegex.FindStringSubmatch(thisSel) - if len(arrayMatches) > 0 { - // Get the key into the map thisSel = arrayMatches[1] @@ -95,14 +81,11 @@ func access(current, selector, value interface{}, isSet, panics bool) interface{ // seriously wrong. Panic. panic("objx: Array index is not an integer. Must use array[int].") } - } } - if curMap, ok := current.(Map); ok { current = map[string]interface{}(curMap) } - // get the object in question switch current.(type) { case map[string]interface{}: @@ -110,39 +93,26 @@ func access(current, selector, value interface{}, isSet, panics bool) interface{ if len(selSegs) <= 1 && isSet { curMSI[thisSel] = value return nil - } else { - current = curMSI[thisSel] } + current = curMSI[thisSel] 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 - } // intFromInterface converts an interface object to the largest @@ -172,8 +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 } -- cgit v1.2.3-1-g7c22