| 102 | } |
| 103 | |
| 104 | func ExamplePointer_Set() { |
| 105 | var doc exampleDocument |
| 106 | |
| 107 | if err := json.Unmarshal(testDocumentJSONBytes, &doc); err != nil { // populates doc |
| 108 | fmt.Println(err) |
| 109 | |
| 110 | return |
| 111 | } |
| 112 | |
| 113 | pointer, err := New("/foo/1") |
| 114 | if err != nil { |
| 115 | fmt.Println(err) |
| 116 | |
| 117 | return |
| 118 | } |
| 119 | |
| 120 | result, err := pointer.Set(&doc, "hey my") |
| 121 | if err != nil { |
| 122 | fmt.Println(err) |
| 123 | |
| 124 | return |
| 125 | } |
| 126 | |
| 127 | fmt.Printf("result: %#v\n", result) |
| 128 | fmt.Printf("doc: %#v\n", doc) |
| 129 | |
| 130 | // Output: |
| 131 | // result: &jsonpointer.exampleDocument{Foo:[]string{"bar", "hey my"}} |
| 132 | // doc: jsonpointer.exampleDocument{Foo:[]string{"bar", "hey my"}} |
| 133 | } |
| 134 | |
| 135 | // ExamplePointer_Set_append demonstrates the RFC 6901 "-" token as an append operation on a slice. |
| 136 | // |