MCPcopy Create free account
hub / github.com/BryanMwangi/pine / searchAnyMethod

Method searchAnyMethod

router.go:210–253  ·  view source on GitHub ↗

searchAnyMethod matches any registered method for OPTIONS/CORS fallback.

(path string, captured []string)

Source from the content-addressed store, hash-verified

208
209// searchAnyMethod matches any registered method for OPTIONS/CORS fallback.
210func (n *node) searchAnyMethod(path string, captured []string) ([]Handler, map[string]string, bool) {
211 if path == "" {
212 for _, h := range n.handlers {
213 return h, buildParams(n.paramNames, captured), true
214 }
215 return nil, nil, false
216 }
217
218 seg, rest := nextSegment(path)
219 if seg == "" {
220 return nil, nil, false
221 }
222
223 firstByte := seg[0]
224
225 if n.children != nil {
226 if child, ok := n.children[firstByte]; ok && strings.HasPrefix(seg, child.path) {
227 remainder := seg[len(child.path):]
228 if remainder == "" {
229 if h, pm, found := child.searchAnyMethod(rest, captured); found {
230 return h, pm, true
231 }
232 } else {
233 if h, pm, found := child.searchAnyMethod(remainder+segSep(rest), captured); found {
234 return h, pm, true
235 }
236 }
237 }
238 }
239
240 if n.paramChild != nil && len(seg) > 0 {
241 if h, pm, found := n.paramChild.searchAnyMethod(rest, append(captured, seg)); found {
242 return h, pm, true
243 }
244 }
245
246 if n.wildcard != nil {
247 for _, h := range n.wildcard.handlers {
248 return h, buildParams(n.wildcard.paramNames, append(captured, path)), true
249 }
250 }
251
252 return nil, nil, false
253}
254
255// nextSegment splits path at the first '/' returning (segment, remainder).
256// The leading '/' in remainder is consumed.

Callers 1

SearchAnyMethodMethod · 0.80

Calls 3

buildParamsFunction · 0.85
nextSegmentFunction · 0.85
segSepFunction · 0.85

Tested by

no test coverage detected