Skip to content

Commit

Permalink
Use gomodules.xyz/orderedmap (#25)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha authored Mar 22, 2020
1 parent e679f79 commit b31198d
Show file tree
Hide file tree
Showing 67 changed files with 19,715 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ env:
- GO111MODULE=on

script:
- cd v2
- cd v3
- go test -v
6 changes: 3 additions & 3 deletions v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.12

require (
github.com/evanphx/json-patch v4.5.0+incompatible
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0
github.com/pkg/errors v0.8.1 // indirect
github.com/stretchr/testify v1.3.0
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.4.0
gomodules.xyz/orderedmap v0.0.0-20200322095732-07fa05d90fd0
)
16 changes: 10 additions & 6 deletions v3/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 h1:i462o439ZjprVSFSZLZxcsoAe592sZB1rci2Z8j4wdk=
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gomodules.xyz/orderedmap v0.0.0-20200322095732-07fa05d90fd0 h1:oM9sKEWG5fuauhaaT4NCdRaieiKjJMe30bV3KTcYA5k=
gomodules.xyz/orderedmap v0.0.0-20200322095732-07fa05d90fd0/go.mod h1:g9/TPUCm1t2gwD3j3zfV8uylyYhVdCNSi+xCEIu7yTU=
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.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
33 changes: 14 additions & 19 deletions v3/jsonpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"reflect"
"strings"

"github.com/iancoleman/orderedmap"
"gomodules.xyz/orderedmap"
)

var errBadJSONDoc = fmt.Errorf("invalid JSON Document")
Expand Down Expand Up @@ -79,9 +79,9 @@ func parse(data []byte) (interface{}, error) {
if err != nil {
return nil, err
}
return aI, nil
return &aI, nil
} else if len(data) > 0 && data[0] == '[' {
var aI []orderedmap.OrderedMap
var aI []*orderedmap.OrderedMap
err := json.Unmarshal(data, &aI)
if err != nil {
return nil, err
Expand Down Expand Up @@ -120,24 +120,24 @@ func matchesValue(av, bv interface{}) bool {
if ok && bt == at {
return true
}
case orderedmap.OrderedMap:
bt, ok := bv.(orderedmap.OrderedMap)
case *orderedmap.OrderedMap:
bt, ok := bv.(*orderedmap.OrderedMap)
if !ok {
return false
}
for _, key := range at.Keys() {
if !matchesValue(get(at, key), get(bt, key)) {
if !matchesValue(at.Entry(key), bt.Entry(key)) {
return false
}
}
for _, key := range bt.Keys() {
if !matchesValue(get(at, key), get(bt, key)) {
if !matchesValue(at.Entry(key), bt.Entry(key)) {
return false
}
}
return true
case []orderedmap.OrderedMap:
bt, ok := bv.([]orderedmap.OrderedMap)
case []*orderedmap.OrderedMap:
bt, ok := bv.([]*orderedmap.OrderedMap)
if !ok {
return false
}
Expand Down Expand Up @@ -178,11 +178,6 @@ func matchesValue(av, bv interface{}) bool {
return false
}

func get(m orderedmap.OrderedMap, key string) interface{} {
v, _ := m.Get(key)
return v
}

// From http://tools.ietf.org/html/rfc6901#section-4 :
//
// Evaluation of each reference token begins by decoding any escaped
Expand Down Expand Up @@ -252,18 +247,18 @@ func handleValues(av, bv interface{}, p string, patch []Operation) ([]Operation,

var err error
switch at := av.(type) {
case orderedmap.OrderedMap:
bt := bv.(orderedmap.OrderedMap)
patch, err = diff(&at, &bt, p, patch)
case *orderedmap.OrderedMap:
bt := bv.(*orderedmap.OrderedMap)
patch, err = diff(at, bt, p, patch)
if err != nil {
return nil, err
}
case string, float64, bool:
if !matchesValue(av, bv) {
patch = append(patch, NewOperation("replace", p, bv))
}
case []orderedmap.OrderedMap:
bt := bv.([]orderedmap.OrderedMap)
case []*orderedmap.OrderedMap:
bt := bv.([]*orderedmap.OrderedMap)
n := min(len(at), len(bt))
for i := len(at) - 1; i >= n; i-- {
patch = append(patch, NewOperation("remove", makePath(p, i), nil))
Expand Down
15 changes: 15 additions & 0 deletions v3/vendor/github.com/davecgh/go-spew/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

152 changes: 152 additions & 0 deletions v3/vendor/github.com/davecgh/go-spew/spew/bypass.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions v3/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b31198d

Please sign in to comment.