-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andy Goldstein <goldsteina@vmware.com>
- Loading branch information
Showing
6 changed files
with
141 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Compiled Object files, Static and Dynamic libs (Shared Objects) | ||
*.o | ||
*.a | ||
*.so | ||
|
||
# Folders | ||
_obj | ||
_test | ||
|
||
# Architecture specific extensions/prefixes | ||
*.[568vq] | ||
[568vq].out | ||
|
||
*.cgo1.go | ||
*.cgo2.c | ||
_cgo_defun.c | ||
_cgo_gotypes.go | ||
_cgo_export.* | ||
|
||
_testmain.go | ||
|
||
*.exe | ||
*.test | ||
*.prof | ||
|
||
/.idea | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: go | ||
go: | ||
- 1.x | ||
- tip | ||
|
||
go_import_path: gomodules.xyz/jsonpatch | ||
|
||
cache: | ||
directories: | ||
- $HOME/.cache/go-build | ||
- $GOPATH/pkg/mod | ||
|
||
env: | ||
- GO111MODULE=on | ||
|
||
script: | ||
- go test -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Change Log | ||
|
||
## [v2.0.0](https://github.com/gomodules/jsonpatch/tree/v2.0.0) (2019-06-25) | ||
[Full Changelog](https://github.com/gomodules/jsonpatch/compare/1.0.0...v2.0.0) | ||
|
||
**Merged pull requests:** | ||
|
||
- Update go.mod and remove vendor folder [\#18](https://github.com/gomodules/jsonpatch/pull/18) ([tamalsaha](https://github.com/tamalsaha)) | ||
- Change package path to gomodules.xyz/jsonpath [\#17](https://github.com/gomodules/jsonpatch/pull/17) ([tamalsaha](https://github.com/tamalsaha)) | ||
- \[Emergency\] correct array index in backtrace [\#16](https://github.com/gomodules/jsonpatch/pull/16) ([kdada](https://github.com/kdada)) | ||
- Added support for arrays at the root [\#15](https://github.com/gomodules/jsonpatch/pull/15) ([e-nikolov](https://github.com/e-nikolov)) | ||
- Fix the example code in readme [\#14](https://github.com/gomodules/jsonpatch/pull/14) ([pytimer](https://github.com/pytimer)) | ||
|
||
## [1.0.0](https://github.com/gomodules/jsonpatch/tree/1.0.0) (2019-01-08) | ||
**Fixed bugs:** | ||
|
||
- Correctly generate patch for nested object [\#8](https://github.com/gomodules/jsonpatch/issues/8) | ||
|
||
**Closed issues:** | ||
|
||
- Do releases and in SemVer [\#12](https://github.com/gomodules/jsonpatch/issues/12) | ||
- Generated patch incorrect for Array replacement [\#1](https://github.com/gomodules/jsonpatch/issues/1) | ||
|
||
**Merged pull requests:** | ||
|
||
- Add JsonPatchOperation as type alias for Operation [\#13](https://github.com/gomodules/jsonpatch/pull/13) ([tamalsaha](https://github.com/tamalsaha)) | ||
- Migrate to go mod [\#10](https://github.com/gomodules/jsonpatch/pull/10) ([tamalsaha](https://github.com/tamalsaha)) | ||
- Add test for nested object [\#9](https://github.com/gomodules/jsonpatch/pull/9) ([tamalsaha](https://github.com/tamalsaha)) | ||
- Add test for edit distance computation [\#7](https://github.com/gomodules/jsonpatch/pull/7) ([tamalsaha](https://github.com/tamalsaha)) | ||
- Append edit distance operations from end to start [\#6](https://github.com/gomodules/jsonpatch/pull/6) ([tamalsaha](https://github.com/tamalsaha)) | ||
- Add travis file [\#4](https://github.com/gomodules/jsonpatch/pull/4) ([tamalsaha](https://github.com/tamalsaha)) | ||
- Run go fmt [\#3](https://github.com/gomodules/jsonpatch/pull/3) ([tamalsaha](https://github.com/tamalsaha)) | ||
- Fix array comparison [\#2](https://github.com/gomodules/jsonpatch/pull/2) ([tamalsaha](https://github.com/tamalsaha)) | ||
|
||
|
||
|
||
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# jsonpatch | ||
|
||
[![Build Status](https://travis-ci.org/gomodules/jsonpatch.svg?branch=master)](https://travis-ci.org/gomodules/jsonpatch) | ||
[![Go Report Card](https://goreportcard.com/badge/gomodules.xyz/jsonpatch "Go Report Card")](https://goreportcard.com/report/gomodules.xyz/jsonpatch) | ||
[![GoDoc](https://godoc.org/gomodules.xyz/jsonpatch?status.svg "GoDoc")](https://godoc.org/gomodules.xyz/jsonpatch) | ||
|
||
As per http://jsonpatch.com JSON Patch is specified in RFC 6902 from the IETF. | ||
|
||
JSON Patch allows you to generate JSON that describes changes you want to make to a document, so you don't have to send the whole doc. JSON Patch format is supported by HTTP PATCH method, allowing for standards based partial updates via REST APIs. | ||
|
||
```console | ||
go get gomodules.xyz/jsonpatch/v2 | ||
``` | ||
|
||
I tried some of the other "jsonpatch" go implementations, but none of them could diff two json documents and generate format like jsonpatch.com specifies. Here's an example of the patch format: | ||
|
||
```json | ||
[ | ||
{ "op": "replace", "path": "/baz", "value": "boo" }, | ||
{ "op": "add", "path": "/hello", "value": ["world"] }, | ||
{ "op": "remove", "path": "/foo"} | ||
] | ||
|
||
``` | ||
The API is super simple | ||
|
||
## example | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"gomodules.xyz/jsonpatch/v2" | ||
) | ||
|
||
var simpleA = `{"a":100, "b":200, "c":"hello"}` | ||
var simpleB = `{"a":100, "b":200, "c":"goodbye"}` | ||
|
||
func main() { | ||
patch, e := jsonpatch.CreatePatch([]byte(simpleA), []byte(simpleB)) | ||
if e != nil { | ||
fmt.Printf("Error creating JSON patch:%v", e) | ||
return | ||
} | ||
for _, operation := range patch { | ||
fmt.Printf("%s\n", operation.Json()) | ||
} | ||
} | ||
``` | ||
|
||
This code needs more tests, as it's a highly recursive, type-fiddly monster. It's not a lot of code, but it has to deal with a lot of complexity. |