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

Method setAt

pointer.go:290–308  ·  view source on GitHub ↗

setAt recursively walks the token list, setting the data at the terminal token and rebinding any new child reference (e.g. a slice header returned by an "-" append) into its parent on the way back up. Returning the (possibly new) node at each level is what makes append work at any depth without req

(node any, tokens []string, data any, nameProvider NameProvider)

Source from the content-addressed store, hash-verified

288// requiring the caller to pass a pointer to the containing slice: the new slice header propagates
289// up and each parent rebinds it via the appropriate kind-specific setter.
290func (p *Pointer) setAt(node any, tokens []string, data any, nameProvider NameProvider) (any, error) {
291 decodedToken := Unescape(tokens[0])
292
293 if len(tokens) == 1 {
294 return setSingleImpl(node, data, decodedToken, nameProvider)
295 }
296
297 child, err := p.resolveNodeForToken(node, decodedToken, nameProvider)
298 if err != nil {
299 return node, err
300 }
301
302 newChild, err := p.setAt(child, tokens[1:], data, nameProvider)
303 if err != nil {
304 return node, err
305 }
306
307 return rebindChild(node, decodedToken, newChild, nameProvider)
308}
309
310// rebindChild writes newChild back into node at decodedToken.
311//

Callers 1

setMethod · 0.95

Calls 4

resolveNodeForTokenMethod · 0.95
UnescapeFunction · 0.85
setSingleImplFunction · 0.85
rebindChildFunction · 0.85

Tested by

no test coverage detected