Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose MakePath function #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions jsonpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func matchesValue(av, bv interface{}) bool {

var rfc6901Encoder = strings.NewReplacer("~", "~0", "/", "~1")

func makePath(path string, newPart interface{}) string {
func MakePath(path string, newPart interface{}) string {
key := rfc6901Encoder.Replace(fmt.Sprintf("%v", newPart))
if path == "" {
return "/" + key
Expand All @@ -150,7 +150,7 @@ func makePath(path string, newPart interface{}) string {
// diff returns the (recursive) difference between a and b as an array of JsonPatchOperations.
func diff(a, b map[string]interface{}, path string, patch []JsonPatchOperation) ([]JsonPatchOperation, error) {
for key, bv := range b {
p := makePath(path, key)
p := MakePath(path, key)
av, ok := a[key]
// value was added
if !ok {
Expand All @@ -173,7 +173,7 @@ func diff(a, b map[string]interface{}, path string, patch []JsonPatchOperation)
for key := range a {
_, found := b[key]
if !found {
p := makePath(path, key)
p := MakePath(path, key)

patch = append(patch, NewPatch("remove", p, nil))
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func handleValues(av, bv interface{}, p string, patch []JsonPatchOperation) ([]J

} else {
for i := range bt {
patch, err = handleValues(at[i], bt[i], makePath(p, i), patch)
patch, err = handleValues(at[i], bt[i], MakePath(p, i), patch)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -236,7 +236,7 @@ func compareArray(av, bv []interface{}, p string) []JsonPatchOperation {
}
}
if !found {
retval = append(retval, NewPatch("remove", makePath(p, i), nil))
retval = append(retval, NewPatch("remove", MakePath(p, i), nil))
}
}

Expand All @@ -249,7 +249,7 @@ func compareArray(av, bv []interface{}, p string) []JsonPatchOperation {
}
}
if !found {
retval = append(retval, NewPatch("add", makePath(p, i), v))
retval = append(retval, NewPatch("add", MakePath(p, i), v))
}
}

Expand Down