Skip to content

Commit

Permalink
docs: add example in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
denouche committed Jan 17, 2023
1 parent af4bcde commit 030bfc9
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,50 @@ go get github.com/denouche/go-json-patch-jsonpath

## Usage

TODO
```golang
package main

import (
"fmt"

jsonpatch "github.com/denouche/go-json-patch-jsonpath"
)

type People struct {
Name string
Age int
}

func NewPeople() *People {
return &People{}
}

func main() {
r := jsonpatch.PatchRequests[People]{
Patches: []*jsonpatch.PatchRequest[People]{
{
Operation: "replace",
Path: "$.name",
Value: "Bar",
},
},
}

person := &People{
Name: "Foo",
Age: 42,
}

patchedPerson, err := r.Apply(person, NewPeople)
if err != nil {
// handle error
}

fmt.Printf("%s %d\n", person.Name, person.Age) // Foo 42
fmt.Printf("%s %d\n", patchedPerson.Name, patchedPerson.Age) // Bar 42
}

```

## References

Expand Down

0 comments on commit 030bfc9

Please sign in to comment.