MCPcopy Index your code
hub / github.com/go-openapi/jsonpointer / ExamplePointer_Set_append

Function ExamplePointer_Set_append

examples_test.go:139–158  ·  view source on GitHub ↗

ExamplePointer_Set_append demonstrates the RFC 6901 "-" token as an append operation on a slice. On nested slices reached through an addressable parent (map entry, pointer to struct, ...), the append is performed in place and the returned document is the same reference.

()

Source from the content-addressed store, hash-verified

137// On nested slices reached through an addressable parent (map entry, pointer to struct, ...), the
138// append is performed in place and the returned document is the same reference.
139func ExamplePointer_Set_append() {
140 doc := map[string]any{"foo": []any{"bar"}}
141
142 pointer, err := New("/foo/-")
143 if err != nil {
144 fmt.Println(err)
145
146 return
147 }
148
149 if _, err := pointer.Set(doc, "baz"); err != nil {
150 fmt.Println(err)
151
152 return
153 }
154
155 fmt.Printf("doc: %v\n", doc["foo"])
156
157 // Output: doc: [bar baz]
158}
159
160// ExamplePointer_Set_appendTopLevelSlice shows the one case where the returned document is
161// load-bearing: appending to a top-level slice passed by value.

Callers

nothing calls this directly

Calls 2

NewFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…