MCPcopy
hub / github.com/gin-gonic/gin / getValue

Method getValue

tree.go:418–665  ·  view source on GitHub ↗

Returns the handle registered with the given path (key). The values of wildcards are saved to a map. If no handle can be found, a TSR (trailing slash redirect) recommendation is made if a handle exists with an extra (without the) trailing slash for the given path.

(path string, params *Params, skippedNodes *[]skippedNode, unescape bool)

Source from the content-addressed store, hash-verified

416// made if a handle exists with an extra (without the) trailing slash for the
417// given path.
418func (n *node) getValue(path string, params *Params, skippedNodes *[]skippedNode, unescape bool) (value nodeValue) {
419 var globalParamsCount int16
420
421walk: // Outer loop for walking the tree
422 for {
423 prefix := n.path
424 if len(path) > len(prefix) {
425 if path[:len(prefix)] == prefix {
426 path = path[len(prefix):]
427
428 // Try all the non-wildcard children first by matching the indices
429 idxc := path[0]
430 for i, c := range []byte(n.indices) {
431 if c == idxc {
432 // strings.HasPrefix(n.children[len(n.children)-1].path, ":") == n.wildChild
433 if n.wildChild {
434 index := len(*skippedNodes)
435 *skippedNodes = (*skippedNodes)[:index+1]
436 (*skippedNodes)[index] = skippedNode{
437 path: prefix + path,
438 node: &node{
439 path: n.path,
440 wildChild: n.wildChild,
441 nType: n.nType,
442 priority: n.priority,
443 children: n.children,
444 handlers: n.handlers,
445 fullPath: n.fullPath,
446 },
447 paramsCount: globalParamsCount,
448 }
449 }
450
451 n = n.children[i]
452 continue walk
453 }
454 }
455
456 if !n.wildChild {
457 // If the path at the end of the loop is not equal to '/' and the current node has no child nodes
458 // the current node needs to roll back to last valid skippedNode
459 if path != "/" {
460 for length := len(*skippedNodes); length > 0; length-- {
461 skippedNode := (*skippedNodes)[length-1]
462 *skippedNodes = (*skippedNodes)[:length-1]
463 if strings.HasSuffix(skippedNode.path, path) {
464 path = skippedNode.path
465 n = skippedNode.node
466 if value.params != nil {
467 *value.params = (*value.params)[:skippedNode.paramsCount]
468 }
469 globalParamsCount = skippedNode.paramsCount
470 continue walk
471 }
472 }
473 }
474
475 // Nothing found.

Callers 8

TestTreeInvalidNodeTypeFunction · 0.95
handleHTTPRequestMethod · 0.80
checkRequestsFunction · 0.80

Calls

no outgoing calls

Tested by 7

TestTreeInvalidNodeTypeFunction · 0.76
checkRequestsFunction · 0.64