Upgrading server dependancies (#8308)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
b112747de7
Коммит
6d8f122a51
8
vendor/github.com/stretchr/objx/.codeclimate.yml
сгенерированный
поставляемый
8
vendor/github.com/stretchr/objx/.codeclimate.yml
сгенерированный
поставляемый
@@ -10,4 +10,12 @@ exclude_patterns:
|
||||
- ".github/"
|
||||
- "vendor/"
|
||||
- "codegen/"
|
||||
- "*.yml"
|
||||
- ".*.yml"
|
||||
- "*.md"
|
||||
- "Gopkg.*"
|
||||
- "doc.go"
|
||||
- "type_specific_codegen_test.go"
|
||||
- "type_specific_codegen.go"
|
||||
- ".gitignore"
|
||||
- "LICENSE"
|
||||
|
||||
13
vendor/github.com/stretchr/objx/.travis.yml
сгенерированный
поставляемый
13
vendor/github.com/stretchr/objx/.travis.yml
сгенерированный
поставляемый
@@ -1,8 +1,9 @@
|
||||
language: go
|
||||
go:
|
||||
- 1.6
|
||||
- 1.7
|
||||
- 1.8
|
||||
- 1.9
|
||||
- tip
|
||||
|
||||
env:
|
||||
global:
|
||||
@@ -14,12 +15,14 @@ before_script:
|
||||
- ./cc-test-reporter before-build
|
||||
|
||||
install:
|
||||
- go get github.com/go-task/task/cmd/task
|
||||
- wget https://github.com/go-task/task/releases/download/v1.4.4/task_linux_amd64.tar.gz
|
||||
- tar xf task_linux_amd64.tar.gz
|
||||
- mv task $HOME/gopath/bin
|
||||
|
||||
script:
|
||||
- task dl-deps
|
||||
- task lint
|
||||
- task test-coverage
|
||||
- task dl-deps
|
||||
- task lint
|
||||
- task test-coverage
|
||||
|
||||
after_script:
|
||||
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
||||
|
||||
2
vendor/github.com/stretchr/objx/README.md
сгенерированный
поставляемый
2
vendor/github.com/stretchr/objx/README.md
сгенерированный
поставляемый
@@ -74,7 +74,7 @@ To update Objx to the latest version, run:
|
||||
go get -u github.com/stretchr/objx
|
||||
|
||||
### Supported go versions
|
||||
We support the lastest two major Go versions, which are 1.8 and 1.9 at the moment.
|
||||
We support the lastest four major Go versions, which are 1.6, 1.7, 1.8 and 1.9 at the moment.
|
||||
|
||||
## Contributing
|
||||
Please feel free to submit issues, fork the repository and send pull requests!
|
||||
|
||||
1
vendor/github.com/stretchr/objx/Taskfile.yml
сгенерированный
поставляемый
1
vendor/github.com/stretchr/objx/Taskfile.yml
сгенерированный
поставляемый
@@ -5,7 +5,6 @@ dl-deps:
|
||||
desc: Downloads cli dependencies
|
||||
cmds:
|
||||
- go get -u github.com/golang/lint/golint
|
||||
- go get -u github.com/golang/dep/cmd/dep
|
||||
|
||||
update-deps:
|
||||
desc: Updates dependencies
|
||||
|
||||
155
vendor/github.com/stretchr/objx/accessors.go
сгенерированный
поставляемый
155
vendor/github.com/stretchr/objx/accessors.go
сгенерированный
поставляемый
@@ -6,9 +6,17 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// arrayAccesRegexString is the regex used to extract the array number
|
||||
// from the access path
|
||||
const arrayAccesRegexString = `^(.+)\[([0-9]+)\]$`
|
||||
const (
|
||||
// PathSeparator is the character used to separate the elements
|
||||
// of the keypath.
|
||||
//
|
||||
// For example, `location.address.city`
|
||||
PathSeparator string = "."
|
||||
|
||||
// arrayAccesRegexString is the regex used to extract the array number
|
||||
// from the access path
|
||||
arrayAccesRegexString = `^(.+)\[([0-9]+)\]$`
|
||||
)
|
||||
|
||||
// arrayAccesRegex is the compiled arrayAccesRegexString
|
||||
var arrayAccesRegex = regexp.MustCompile(arrayAccesRegexString)
|
||||
@@ -46,103 +54,60 @@ func (m Map) Set(selector string, value interface{}) Map {
|
||||
return m
|
||||
}
|
||||
|
||||
// getIndex returns the index, which is hold in s by two braches.
|
||||
// It also returns s withour the index part, e.g. name[1] will return (1, name).
|
||||
// If no index is found, -1 is returned
|
||||
func getIndex(s string) (int, string) {
|
||||
arrayMatches := arrayAccesRegex.FindStringSubmatch(s)
|
||||
if len(arrayMatches) > 0 {
|
||||
// Get the key into the map
|
||||
selector := arrayMatches[1]
|
||||
// Get the index into the array at the key
|
||||
// We know this cannt fail because arrayMatches[2] is an int for sure
|
||||
index, _ := strconv.Atoi(arrayMatches[2])
|
||||
return index, selector
|
||||
}
|
||||
return -1, s
|
||||
}
|
||||
|
||||
// access accesses the object using the selector and performs the
|
||||
// appropriate action.
|
||||
func access(current, selector, value interface{}, isSet bool) interface{} {
|
||||
switch selector.(type) {
|
||||
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
|
||||
func access(current interface{}, selector string, value interface{}, isSet bool) interface{} {
|
||||
selSegs := strings.SplitN(selector, PathSeparator, 2)
|
||||
thisSel := selSegs[0]
|
||||
index := -1
|
||||
|
||||
if strings.Contains(thisSel, "[") {
|
||||
index, thisSel = getIndex(thisSel)
|
||||
}
|
||||
|
||||
if curMap, ok := current.(Map); ok {
|
||||
current = map[string]interface{}(curMap)
|
||||
}
|
||||
// get the object in question
|
||||
switch current.(type) {
|
||||
case map[string]interface{}:
|
||||
curMSI := current.(map[string]interface{})
|
||||
if len(selSegs) <= 1 && isSet {
|
||||
curMSI[thisSel] = value
|
||||
return nil
|
||||
}
|
||||
current = curMSI[thisSel]
|
||||
default:
|
||||
current = nil
|
||||
}
|
||||
// do we need to access the item of an array?
|
||||
if index > -1 {
|
||||
if array, ok := current.([]interface{}); ok {
|
||||
index := intFromInterface(selector)
|
||||
if 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
|
||||
|
||||
if strings.Contains(thisSel, "[") {
|
||||
arrayMatches := arrayAccesRegex.FindStringSubmatch(thisSel)
|
||||
if len(arrayMatches) > 0 {
|
||||
// Get the key into the map
|
||||
thisSel = arrayMatches[1]
|
||||
|
||||
// Get the index into the array at the key
|
||||
index, err = strconv.Atoi(arrayMatches[2])
|
||||
|
||||
if err != nil {
|
||||
// This should never happen. If it does, something has gone
|
||||
// seriously wrong. Panic.
|
||||
panic("objx: Array index is not an integer. Must use array[int].")
|
||||
}
|
||||
if index < len(array) {
|
||||
current = array[index]
|
||||
} else {
|
||||
current = nil
|
||||
}
|
||||
}
|
||||
if curMap, ok := current.(Map); ok {
|
||||
current = map[string]interface{}(curMap)
|
||||
}
|
||||
// get the object in question
|
||||
switch current.(type) {
|
||||
case map[string]interface{}:
|
||||
curMSI := current.(map[string]interface{})
|
||||
if len(selSegs) <= 1 && isSet {
|
||||
curMSI[thisSel] = value
|
||||
return nil
|
||||
}
|
||||
current = curMSI[thisSel]
|
||||
default:
|
||||
current = nil
|
||||
}
|
||||
// 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 {
|
||||
current = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(selSegs) > 1 {
|
||||
current = access(current, selSegs[1], value, isSet)
|
||||
}
|
||||
}
|
||||
if len(selSegs) > 1 {
|
||||
current = access(current, selSegs[1], value, isSet)
|
||||
}
|
||||
return current
|
||||
}
|
||||
|
||||
// intFromInterface converts an interface object to the largest
|
||||
// representation of an unsigned integer using a type switch and
|
||||
// assertions
|
||||
func intFromInterface(selector interface{}) int {
|
||||
var value int
|
||||
switch selector.(type) {
|
||||
case int:
|
||||
value = selector.(int)
|
||||
case int8:
|
||||
value = int(selector.(int8))
|
||||
case int16:
|
||||
value = int(selector.(int16))
|
||||
case int32:
|
||||
value = int(selector.(int32))
|
||||
case int64:
|
||||
value = int(selector.(int64))
|
||||
case uint:
|
||||
value = int(selector.(uint))
|
||||
case uint8:
|
||||
value = int(selector.(uint8))
|
||||
case uint16:
|
||||
value = int(selector.(uint16))
|
||||
case uint32:
|
||||
value = int(selector.(uint32))
|
||||
case uint64:
|
||||
value = int(selector.(uint64))
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
204
vendor/github.com/stretchr/objx/accessors_test.go
сгенерированный
поставляемый
204
vendor/github.com/stretchr/objx/accessors_test.go
сгенерированный
поставляемый
@@ -1,238 +1,174 @@
|
||||
package objx
|
||||
package objx_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/objx"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAccessorsAccessGetSingleField(t *testing.T) {
|
||||
current := Map{"name": "Tyler"}
|
||||
m := objx.Map{"name": "Tyler"}
|
||||
|
||||
assert.Equal(t, "Tyler", current.Get("name").Data())
|
||||
assert.Equal(t, "Tyler", m.Get("name").Data())
|
||||
}
|
||||
|
||||
func TestAccessorsAccessGetSingleFieldInt(t *testing.T) {
|
||||
current := Map{"name": 10}
|
||||
m := objx.Map{"name": 10}
|
||||
|
||||
assert.Equal(t, 10, current.Get("name").Data())
|
||||
assert.Equal(t, 10, m.Get("name").Data())
|
||||
}
|
||||
|
||||
func TestAccessorsAccessGetDeep(t *testing.T) {
|
||||
current := Map{
|
||||
"name": Map{
|
||||
m := objx.Map{
|
||||
"name": objx.Map{
|
||||
"first": "Tyler",
|
||||
"last": "Bunnell",
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, "Tyler", current.Get("name.first").Data())
|
||||
assert.Equal(t, "Bunnell", current.Get("name.last").Data())
|
||||
assert.Equal(t, "Tyler", m.Get("name.first").Data())
|
||||
assert.Equal(t, "Bunnell", m.Get("name.last").Data())
|
||||
}
|
||||
|
||||
func TestAccessorsAccessGetDeepDeep(t *testing.T) {
|
||||
current := Map{
|
||||
"one": Map{
|
||||
"two": Map{
|
||||
"three": Map{
|
||||
m := objx.Map{
|
||||
"one": objx.Map{
|
||||
"two": objx.Map{
|
||||
"three": objx.Map{
|
||||
"four": 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, 4, current.Get("one.two.three.four").Data())
|
||||
assert.Equal(t, 4, m.Get("one.two.three.four").Data())
|
||||
}
|
||||
|
||||
func TestAccessorsAccessGetInsideArray(t *testing.T) {
|
||||
current := Map{
|
||||
m := objx.Map{
|
||||
"names": []interface{}{
|
||||
Map{
|
||||
objx.Map{
|
||||
"first": "Tyler",
|
||||
"last": "Bunnell",
|
||||
},
|
||||
Map{
|
||||
objx.Map{
|
||||
"first": "Capitol",
|
||||
"last": "Bollocks",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, "Tyler", current.Get("names[0].first").Data())
|
||||
assert.Equal(t, "Bunnell", current.Get("names[0].last").Data())
|
||||
assert.Equal(t, "Capitol", current.Get("names[1].first").Data())
|
||||
assert.Equal(t, "Bollocks", current.Get("names[1].last").Data())
|
||||
assert.Equal(t, "Tyler", m.Get("names[0].first").Data())
|
||||
assert.Equal(t, "Bunnell", m.Get("names[0].last").Data())
|
||||
assert.Equal(t, "Capitol", m.Get("names[1].first").Data())
|
||||
assert.Equal(t, "Bollocks", m.Get("names[1].last").Data())
|
||||
|
||||
assert.Nil(t, current.Get("names[2]").Data())
|
||||
}
|
||||
|
||||
func TestAccessorsAccessGetFromArrayWithInt(t *testing.T) {
|
||||
current := []interface{}{
|
||||
map[string]interface{}{
|
||||
"first": "Tyler",
|
||||
"last": "Bunnell",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"first": "Capitol",
|
||||
"last": "Bollocks",
|
||||
},
|
||||
}
|
||||
one := access(current, 0, nil, false)
|
||||
two := access(current, 1, nil, false)
|
||||
three := access(current, 2, nil, false)
|
||||
|
||||
assert.Equal(t, "Tyler", one.(map[string]interface{})["first"])
|
||||
assert.Equal(t, "Capitol", two.(map[string]interface{})["first"])
|
||||
assert.Nil(t, three)
|
||||
}
|
||||
|
||||
func TestAccessorsAccessGetFromArrayWithIntTypes(t *testing.T) {
|
||||
current := []interface{}{
|
||||
"abc",
|
||||
"def",
|
||||
}
|
||||
assert.Equal(t, "abc", access(current, 0, nil, false))
|
||||
assert.Equal(t, "def", access(current, 1, nil, false))
|
||||
assert.Nil(t, access(current, 2, nil, false))
|
||||
|
||||
assert.Equal(t, "abc", access(current, int8(0), nil, false))
|
||||
assert.Equal(t, "def", access(current, int8(1), nil, false))
|
||||
assert.Nil(t, access(current, int8(2), nil, false))
|
||||
|
||||
assert.Equal(t, "abc", access(current, int16(0), nil, false))
|
||||
assert.Equal(t, "def", access(current, int16(1), nil, false))
|
||||
assert.Nil(t, access(current, int16(2), nil, false))
|
||||
|
||||
assert.Equal(t, "abc", access(current, int32(0), nil, false))
|
||||
assert.Equal(t, "def", access(current, int32(1), nil, false))
|
||||
assert.Nil(t, access(current, int32(2), nil, false))
|
||||
|
||||
assert.Equal(t, "abc", access(current, int64(0), nil, false))
|
||||
assert.Equal(t, "def", access(current, int64(1), nil, false))
|
||||
assert.Nil(t, access(current, int64(2), nil, false))
|
||||
|
||||
assert.Equal(t, "abc", access(current, uint(0), nil, false))
|
||||
assert.Equal(t, "def", access(current, uint(1), nil, false))
|
||||
assert.Nil(t, access(current, uint(2), nil, false))
|
||||
|
||||
assert.Equal(t, "abc", access(current, uint8(0), nil, false))
|
||||
assert.Equal(t, "def", access(current, uint8(1), nil, false))
|
||||
assert.Nil(t, access(current, uint8(2), nil, false))
|
||||
|
||||
assert.Equal(t, "abc", access(current, uint16(0), nil, false))
|
||||
assert.Equal(t, "def", access(current, uint16(1), nil, false))
|
||||
assert.Nil(t, access(current, uint16(2), nil, false))
|
||||
|
||||
assert.Equal(t, "abc", access(current, uint32(0), nil, false))
|
||||
assert.Equal(t, "def", access(current, uint32(1), nil, false))
|
||||
assert.Nil(t, access(current, uint32(2), nil, false))
|
||||
|
||||
assert.Equal(t, "abc", access(current, uint64(0), nil, false))
|
||||
assert.Equal(t, "def", access(current, uint64(1), nil, false))
|
||||
assert.Nil(t, access(current, uint64(2), nil, false))
|
||||
}
|
||||
|
||||
func TestAccessorsAccessGetFromArrayWithIntError(t *testing.T) {
|
||||
current := Map{"name": "Tyler"}
|
||||
|
||||
assert.Nil(t, access(current, 0, nil, false))
|
||||
assert.Nil(t, m.Get("names[2]").Data())
|
||||
assert.Nil(t, m.Get("names[]").Data())
|
||||
assert.Nil(t, m.Get("names1]]").Data())
|
||||
assert.Nil(t, m.Get("names[1]]").Data())
|
||||
assert.Nil(t, m.Get("names[[1]]").Data())
|
||||
assert.Nil(t, m.Get("names[[1]").Data())
|
||||
assert.Nil(t, m.Get("names[[1").Data())
|
||||
}
|
||||
|
||||
func TestAccessorsGet(t *testing.T) {
|
||||
current := Map{"name": "Tyler"}
|
||||
m := objx.Map{"name": "Tyler"}
|
||||
|
||||
assert.Equal(t, "Tyler", current.Get("name").Data())
|
||||
assert.Equal(t, "Tyler", m.Get("name").Data())
|
||||
}
|
||||
|
||||
func TestAccessorsAccessSetSingleField(t *testing.T) {
|
||||
current := Map{"name": "Tyler"}
|
||||
m := objx.Map{"name": "Tyler"}
|
||||
|
||||
current.Set("name", "Mat")
|
||||
current.Set("age", 29)
|
||||
m.Set("name", "Mat")
|
||||
m.Set("age", 29)
|
||||
|
||||
assert.Equal(t, current["name"], "Mat")
|
||||
assert.Equal(t, current["age"], 29)
|
||||
assert.Equal(t, m.Get("name").Data(), "Mat")
|
||||
assert.Equal(t, m.Get("age").Data(), 29)
|
||||
}
|
||||
|
||||
func TestAccessorsAccessSetSingleFieldNotExisting(t *testing.T) {
|
||||
current := Map{
|
||||
m := objx.Map{
|
||||
"first": "Tyler",
|
||||
"last": "Bunnell",
|
||||
}
|
||||
|
||||
current.Set("name", "Mat")
|
||||
m.Set("name", "Mat")
|
||||
|
||||
assert.Equal(t, current["name"], "Mat")
|
||||
assert.Equal(t, m.Get("name").Data(), "Mat")
|
||||
}
|
||||
|
||||
func TestAccessorsAccessSetDeep(t *testing.T) {
|
||||
current := Map{
|
||||
"name": Map{
|
||||
m := objx.Map{
|
||||
"name": objx.Map{
|
||||
"first": "Tyler",
|
||||
"last": "Bunnell",
|
||||
},
|
||||
}
|
||||
|
||||
current.Set("name.first", "Mat")
|
||||
current.Set("name.last", "Ryer")
|
||||
m.Set("name.first", "Mat")
|
||||
m.Set("name.last", "Ryer")
|
||||
|
||||
assert.Equal(t, "Mat", current.Get("name.first").Data())
|
||||
assert.Equal(t, "Ryer", current.Get("name.last").Data())
|
||||
assert.Equal(t, "Mat", m.Get("name.first").Data())
|
||||
assert.Equal(t, "Ryer", m.Get("name.last").Data())
|
||||
}
|
||||
|
||||
func TestAccessorsAccessSetDeepDeep(t *testing.T) {
|
||||
current := Map{
|
||||
"one": Map{
|
||||
"two": Map{
|
||||
"three": Map{
|
||||
"four": 4},
|
||||
m := objx.Map{
|
||||
"one": objx.Map{
|
||||
"two": objx.Map{
|
||||
"three": objx.Map{
|
||||
"four": 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
current.Set("one.two.three.four", 5)
|
||||
m.Set("one.two.three.four", 5)
|
||||
|
||||
assert.Equal(t, 5, current.Get("one.two.three.four").Data())
|
||||
assert.Equal(t, 5, m.Get("one.two.three.four").Data())
|
||||
}
|
||||
|
||||
func TestAccessorsAccessSetArray(t *testing.T) {
|
||||
current := Map{
|
||||
m := objx.Map{
|
||||
"names": []interface{}{"Tyler"},
|
||||
}
|
||||
current.Set("names[0]", "Mat")
|
||||
m.Set("names[0]", "Mat")
|
||||
|
||||
assert.Equal(t, "Mat", current.Get("names[0]").Data())
|
||||
assert.Equal(t, "Mat", m.Get("names[0]").Data())
|
||||
}
|
||||
|
||||
func TestAccessorsAccessSetInsideArray(t *testing.T) {
|
||||
current := Map{
|
||||
m := objx.Map{
|
||||
"names": []interface{}{
|
||||
Map{
|
||||
objx.Map{
|
||||
"first": "Tyler",
|
||||
"last": "Bunnell",
|
||||
},
|
||||
Map{
|
||||
objx.Map{
|
||||
"first": "Capitol",
|
||||
"last": "Bollocks",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
current.Set("names[0].first", "Mat")
|
||||
current.Set("names[0].last", "Ryer")
|
||||
current.Set("names[1].first", "Captain")
|
||||
current.Set("names[1].last", "Underpants")
|
||||
m.Set("names[0].first", "Mat")
|
||||
m.Set("names[0].last", "Ryer")
|
||||
m.Set("names[1].first", "Captain")
|
||||
m.Set("names[1].last", "Underpants")
|
||||
|
||||
assert.Equal(t, "Mat", current.Get("names[0].first").Data())
|
||||
assert.Equal(t, "Ryer", current.Get("names[0].last").Data())
|
||||
assert.Equal(t, "Captain", current.Get("names[1].first").Data())
|
||||
assert.Equal(t, "Underpants", current.Get("names[1].last").Data())
|
||||
assert.Equal(t, "Mat", m.Get("names[0].first").Data())
|
||||
assert.Equal(t, "Ryer", m.Get("names[0].last").Data())
|
||||
assert.Equal(t, "Captain", m.Get("names[1].first").Data())
|
||||
assert.Equal(t, "Underpants", m.Get("names[1].last").Data())
|
||||
}
|
||||
|
||||
func TestAccessorsSet(t *testing.T) {
|
||||
current := Map{"name": "Tyler"}
|
||||
m := objx.Map{"name": "Tyler"}
|
||||
|
||||
current.Set("name", "Mat")
|
||||
m.Set("name", "Mat")
|
||||
|
||||
assert.Equal(t, "Mat", current.Get("name").data)
|
||||
assert.Equal(t, "Mat", m.Get("name").Data())
|
||||
}
|
||||
|
||||
155
vendor/github.com/stretchr/objx/codegen/template_test.txt
сгенерированный
поставляемый
155
vendor/github.com/stretchr/objx/codegen/template_test.txt
сгенерированный
поставляемый
@@ -1,121 +1,120 @@
|
||||
/*
|
||||
Tests for {4} ({1} and []{1})
|
||||
*/
|
||||
|
||||
func Test{4}(t *testing.T) {
|
||||
val := {1}( {2} )
|
||||
val := {1}({2})
|
||||
m := objx.Map{"value": val, "nothing": nil}
|
||||
|
||||
m := map[string]interface{}{"value": val, "nothing": nil}
|
||||
assert.Equal(t, val, New(m).Get("value").{4}())
|
||||
assert.Equal(t, val, New(m).Get("value").Must{4}())
|
||||
assert.Equal(t, {1}({3}), New(m).Get("nothing").{4}())
|
||||
assert.Equal(t, val, New(m).Get("nothing").{4}({2}))
|
||||
assert.Panics(t, func() {
|
||||
New(m).Get("age").Must{4}()
|
||||
})
|
||||
assert.Equal(t, val, m.Get("value").{4}())
|
||||
assert.Equal(t, val, m.Get("value").Must{4}())
|
||||
assert.Equal(t, {1}({3}), m.Get("nothing").{4}())
|
||||
assert.Equal(t, val, m.Get("nothing").{4}({2}))
|
||||
assert.Panics(t, func() {
|
||||
m.Get("age").Must{4}()
|
||||
})
|
||||
}
|
||||
|
||||
func Test{4}Slice(t *testing.T) {
|
||||
val := {1}( {2} )
|
||||
val := {1}({2})
|
||||
m := objx.Map{"value": []{1}{ val }, "nothing": nil}
|
||||
|
||||
m := map[string]interface{}{"value": []{1}{ val }, "nothing": nil}
|
||||
assert.Equal(t, val, New(m).Get("value").{4}Slice()[0])
|
||||
assert.Equal(t, val, New(m).Get("value").Must{4}Slice()[0])
|
||||
assert.Equal(t, []{1}(nil), New(m).Get("nothing").{4}Slice())
|
||||
assert.Equal(t, val, New(m).Get("nothing").{4}Slice( []{1}{ {1}({2}) } )[0])
|
||||
assert.Panics(t, func() {
|
||||
New(m).Get("nothing").Must{4}Slice()
|
||||
})
|
||||
assert.Equal(t, val, m.Get("value").{4}Slice()[0])
|
||||
assert.Equal(t, val, m.Get("value").Must{4}Slice()[0])
|
||||
assert.Equal(t, []{1}(nil), m.Get("nothing").{4}Slice())
|
||||
assert.Equal(t, val, m.Get("nothing").{4}Slice([]{1}{{1}({2})})[0])
|
||||
assert.Panics(t, func() {
|
||||
m.Get("nothing").Must{4}Slice()
|
||||
})
|
||||
}
|
||||
|
||||
func TestIs{4}(t *testing.T) {
|
||||
v := &Value{data: {1}({2})}
|
||||
assert.True(t, v.Is{4}())
|
||||
m := objx.Map{"data": {1}({2})}
|
||||
|
||||
assert.True(t, m.Get("data").Is{4}())
|
||||
}
|
||||
|
||||
func TestIs{4}Slice(t *testing.T) {
|
||||
v := &Value{data: []{1}{ {1}({2}) }}
|
||||
assert.True(t, v.Is{4}Slice())
|
||||
m := objx.Map{"data": []{1}{{1}({2})}}
|
||||
|
||||
assert.True(t, m.Get("data").Is{4}Slice())
|
||||
}
|
||||
|
||||
func TestEach{4}(t *testing.T) {
|
||||
v := &Value{data: []{1}{ {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}) }}
|
||||
count := 0
|
||||
replacedVals := make([]{1}, 0)
|
||||
assert.Equal(t, v, v.Each{4}(func(i int, val {1}) bool {
|
||||
count++
|
||||
replacedVals = append(replacedVals, val)
|
||||
m := objx.Map{"data": []{1}{{1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2})}}
|
||||
count := 0
|
||||
replacedVals := make([]{1}, 0)
|
||||
assert.Equal(t, m.Get("data"), m.Get("data").Each{4}(func(i int, val {1}) bool {
|
||||
count++
|
||||
replacedVals = append(replacedVals, val)
|
||||
|
||||
// abort early
|
||||
// abort early
|
||||
return i != 2
|
||||
}))
|
||||
}))
|
||||
|
||||
assert.Equal(t, count, 3)
|
||||
assert.Equal(t, replacedVals[0], v.Must{4}Slice()[0])
|
||||
assert.Equal(t, replacedVals[1], v.Must{4}Slice()[1])
|
||||
assert.Equal(t, replacedVals[2], v.Must{4}Slice()[2])
|
||||
assert.Equal(t, count, 3)
|
||||
assert.Equal(t, replacedVals[0], m.Get("data").Must{4}Slice()[0])
|
||||
assert.Equal(t, replacedVals[1], m.Get("data").Must{4}Slice()[1])
|
||||
assert.Equal(t, replacedVals[2], m.Get("data").Must{4}Slice()[2])
|
||||
}
|
||||
|
||||
func TestWhere{4}(t *testing.T) {
|
||||
v := &Value{data: []{1}{ {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}) }}
|
||||
m := objx.Map{"data": []{1}{{1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2})}}
|
||||
|
||||
selected := v.Where{4}(func(i int, val {1}) bool {
|
||||
return i%2==0
|
||||
}).Must{4}Slice()
|
||||
selected := m.Get("data").Where{4}(func(i int, val {1}) bool {
|
||||
return i%2 == 0
|
||||
}).Must{4}Slice()
|
||||
|
||||
assert.Equal(t, 3, len(selected))
|
||||
assert.Equal(t, 3, len(selected))
|
||||
}
|
||||
|
||||
func TestGroup{4}(t *testing.T) {
|
||||
v := &Value{data: []{1}{ {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}) }}
|
||||
m := objx.Map{"data": []{1}{{1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2})}}
|
||||
|
||||
grouped := v.Group{4}(func(i int, val {1}) string {
|
||||
return fmt.Sprintf("%v", i%2==0)
|
||||
}).data.(map[string][]{1})
|
||||
grouped := m.Get("data").Group{4}(func(i int, val {1}) string {
|
||||
return fmt.Sprintf("%v", i%2==0)
|
||||
}).Data().(map[string][]{1})
|
||||
|
||||
assert.Equal(t, 2, len(grouped))
|
||||
assert.Equal(t, 3, len(grouped["true"]))
|
||||
assert.Equal(t, 3, len(grouped["false"]))
|
||||
assert.Equal(t, 2, len(grouped))
|
||||
assert.Equal(t, 3, len(grouped["true"]))
|
||||
assert.Equal(t, 3, len(grouped["false"]))
|
||||
}
|
||||
|
||||
func TestReplace{4}(t *testing.T) {
|
||||
v := &Value{data: []{1}{ {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}) }}
|
||||
m := objx.Map{"data": []{1}{{1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2})}}
|
||||
rawArr := m.Get("data").Must{4}Slice()
|
||||
|
||||
rawArr := v.Must{4}Slice()
|
||||
replaced := m.Get("data").Replace{4}(func(index int, val {1}) {1} {
|
||||
if index < len(rawArr)-1 {
|
||||
return rawArr[index+1]
|
||||
}
|
||||
return rawArr[0]
|
||||
})
|
||||
replacedArr := replaced.Must{4}Slice()
|
||||
|
||||
replaced := v.Replace{4}(func(index int, val {1}) {1} {
|
||||
if index < len(rawArr)-1 {
|
||||
return rawArr[index+1]
|
||||
}
|
||||
return rawArr[0]
|
||||
})
|
||||
|
||||
replacedArr := replaced.Must{4}Slice()
|
||||
if assert.Equal(t, 6, len(replacedArr)) {
|
||||
assert.Equal(t, replacedArr[0], rawArr[1])
|
||||
assert.Equal(t, replacedArr[1], rawArr[2])
|
||||
assert.Equal(t, replacedArr[2], rawArr[3])
|
||||
assert.Equal(t, replacedArr[3], rawArr[4])
|
||||
assert.Equal(t, replacedArr[4], rawArr[5])
|
||||
assert.Equal(t, replacedArr[5], rawArr[0])
|
||||
}
|
||||
if assert.Equal(t, 6, len(replacedArr)) {
|
||||
assert.Equal(t, replacedArr[0], rawArr[1])
|
||||
assert.Equal(t, replacedArr[1], rawArr[2])
|
||||
assert.Equal(t, replacedArr[2], rawArr[3])
|
||||
assert.Equal(t, replacedArr[3], rawArr[4])
|
||||
assert.Equal(t, replacedArr[4], rawArr[5])
|
||||
assert.Equal(t, replacedArr[5], rawArr[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollect{4}(t *testing.T) {
|
||||
v := &Value{data: []{1}{ {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}) }}
|
||||
m := objx.Map{"data": []{1}{{1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2}), {1}({2})}}
|
||||
|
||||
collected := v.Collect{4}(func(index int, val {1}) interface{} {
|
||||
return index
|
||||
})
|
||||
collected := m.Get("data").Collect{4}(func(index int, val {1}) interface{} {
|
||||
return index
|
||||
})
|
||||
collectedArr := collected.MustInterSlice()
|
||||
|
||||
collectedArr := collected.MustInterSlice()
|
||||
if assert.Equal(t, 6, len(collectedArr)) {
|
||||
assert.Equal(t, collectedArr[0], 0)
|
||||
assert.Equal(t, collectedArr[1], 1)
|
||||
assert.Equal(t, collectedArr[2], 2)
|
||||
assert.Equal(t, collectedArr[3], 3)
|
||||
assert.Equal(t, collectedArr[4], 4)
|
||||
assert.Equal(t, collectedArr[5], 5)
|
||||
}
|
||||
if assert.Equal(t, 6, len(collectedArr)) {
|
||||
assert.Equal(t, collectedArr[0], 0)
|
||||
assert.Equal(t, collectedArr[1], 1)
|
||||
assert.Equal(t, collectedArr[2], 2)
|
||||
assert.Equal(t, collectedArr[3], 3)
|
||||
assert.Equal(t, collectedArr[4], 4)
|
||||
assert.Equal(t, collectedArr[5], 5)
|
||||
}
|
||||
}
|
||||
|
||||
2
vendor/github.com/stretchr/objx/codegen/types_list.txt
сгенерированный
поставляемый
2
vendor/github.com/stretchr/objx/codegen/types_list.txt
сгенерированный
поставляемый
@@ -1,6 +1,6 @@
|
||||
Interface,interface{},"something",nil,Inter
|
||||
Map,map[string]interface{},map[string]interface{}{"name":"Tyler"},nil,MSI
|
||||
ObjxMap,(Map),New(1),New(nil),ObjxMap
|
||||
ObjxMap,(objx.Map),objx.New(1),objx.New(nil),ObjxMap
|
||||
Bool,bool,true,false,Bool
|
||||
String,string,"hello","",Str
|
||||
Int,int,1,0,Int
|
||||
|
||||
13
vendor/github.com/stretchr/objx/constants.go
сгенерированный
поставляемый
13
vendor/github.com/stretchr/objx/constants.go
сгенерированный
поставляемый
@@ -1,13 +0,0 @@
|
||||
package objx
|
||||
|
||||
const (
|
||||
// PathSeparator is the character used to separate the elements
|
||||
// of the keypath.
|
||||
//
|
||||
// For example, `location.address.city`
|
||||
PathSeparator string = "."
|
||||
|
||||
// SignatureSeparator is the character that is used to
|
||||
// separate the Base64 string from the security signature.
|
||||
SignatureSeparator = "_"
|
||||
)
|
||||
9
vendor/github.com/stretchr/objx/conversions.go
сгенерированный
поставляемый
9
vendor/github.com/stretchr/objx/conversions.go
сгенерированный
поставляемый
@@ -9,6 +9,10 @@ import (
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// SignatureSeparator is the character that is used to
|
||||
// separate the Base64 string from the security signature.
|
||||
const SignatureSeparator = "_"
|
||||
|
||||
// JSON converts the contained object to a JSON string
|
||||
// representation
|
||||
func (m Map) JSON() (string, error) {
|
||||
@@ -40,10 +44,7 @@ func (m Map) Base64() (string, error) {
|
||||
}
|
||||
|
||||
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
|
||||
_, err = encoder.Write([]byte(jsonData))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
_, _ = encoder.Write([]byte(jsonData))
|
||||
_ = encoder.Close()
|
||||
|
||||
return buf.String(), nil
|
||||
|
||||
44
vendor/github.com/stretchr/objx/map.go
сгенерированный
поставляемый
44
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
|
||||
|
||||
55
vendor/github.com/stretchr/objx/map_test.go
сгенерированный
поставляемый
55
vendor/github.com/stretchr/objx/map_test.go
сгенерированный
поставляемый
@@ -92,6 +92,61 @@ func TestMapFromJSONWithError(t *testing.T) {
|
||||
assert.Nil(t, m)
|
||||
}
|
||||
|
||||
func TestConversionJSONInt(t *testing.T) {
|
||||
jsonString :=
|
||||
`{
|
||||
"a": 1,
|
||||
"b": {
|
||||
"data": 1
|
||||
},
|
||||
"c": [1],
|
||||
"d": [[1]]
|
||||
}`
|
||||
m, err := objx.FromJSON(jsonString)
|
||||
|
||||
assert.Nil(t, err)
|
||||
require.NotNil(t, m)
|
||||
assert.Equal(t, 1, m.Get("a").Int())
|
||||
assert.Equal(t, 1, m.Get("b.data").Int())
|
||||
|
||||
assert.True(t, m.Get("c").IsInterSlice())
|
||||
assert.Equal(t, 1, m.Get("c").InterSlice()[0])
|
||||
|
||||
assert.True(t, m.Get("d").IsInterSlice())
|
||||
assert.Equal(t, []interface{}{1}, m.Get("d").InterSlice()[0])
|
||||
}
|
||||
|
||||
func TestJSONSliceInt(t *testing.T) {
|
||||
jsonString :=
|
||||
`{
|
||||
"a": [
|
||||
{"b": 1},
|
||||
{"c": 2}
|
||||
]
|
||||
}`
|
||||
m, err := objx.FromJSON(jsonString)
|
||||
|
||||
assert.Nil(t, err)
|
||||
require.NotNil(t, m)
|
||||
assert.Equal(t, []objx.Map{objx.Map{"b": 1}, objx.Map{"c": 2}}, m.Get("a").ObjxMapSlice())
|
||||
}
|
||||
|
||||
func TestJSONSliceMixed(t *testing.T) {
|
||||
jsonString :=
|
||||
`{
|
||||
"a": [
|
||||
{"b": 1},
|
||||
"a"
|
||||
]
|
||||
}`
|
||||
m, err := objx.FromJSON(jsonString)
|
||||
|
||||
assert.Nil(t, err)
|
||||
require.NotNil(t, m)
|
||||
|
||||
assert.Nil(t, m.Get("a").ObjxMapSlice())
|
||||
}
|
||||
|
||||
func TestMapFromBase64String(t *testing.T) {
|
||||
base64String := "eyJuYW1lIjoiTWF0In0="
|
||||
o, err := objx.FromBase64(base64String)
|
||||
|
||||
23
vendor/github.com/stretchr/objx/type_specific_codegen.go
сгенерированный
поставляемый
23
vendor/github.com/stretchr/objx/type_specific_codegen.go
сгенерированный
поставляемый
@@ -276,13 +276,28 @@ func (v *Value) MustObjxMap() Map {
|
||||
// ObjxMapSlice gets the value as a [](Map), returns the optionalDefault
|
||||
// value or nil if the value is not a [](Map).
|
||||
func (v *Value) ObjxMapSlice(optionalDefault ...[](Map)) [](Map) {
|
||||
if s, ok := v.data.([](Map)); ok {
|
||||
if s, ok := v.data.([]Map); ok {
|
||||
return s
|
||||
}
|
||||
if len(optionalDefault) == 1 {
|
||||
return optionalDefault[0]
|
||||
s, ok := v.data.([]interface{})
|
||||
if !ok {
|
||||
if len(optionalDefault) == 1 {
|
||||
return optionalDefault[0]
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
result := make([]Map, len(s))
|
||||
for i := range s {
|
||||
switch s[i].(type) {
|
||||
case Map:
|
||||
result[i] = s[i].(Map)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// MustObjxMapSlice gets the value as a [](Map).
|
||||
|
||||
3226
vendor/github.com/stretchr/objx/type_specific_codegen_test.go
сгенерированный
поставляемый
3226
vendor/github.com/stretchr/objx/type_specific_codegen_test.go
сгенерированный
поставляемый
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Ссылка в новой задаче
Block a user