| 576 | } |
| 577 | |
| 578 | func (n *node) findPattern(pattern string) bool { |
| 579 | nn := n |
| 580 | for _, nds := range nn.children { |
| 581 | if len(nds) == 0 { |
| 582 | continue |
| 583 | } |
| 584 | |
| 585 | n = nn.findEdge(nds[0].typ, pattern[0]) |
| 586 | if n == nil { |
| 587 | continue |
| 588 | } |
| 589 | |
| 590 | var idx int |
| 591 | var xpattern string |
| 592 | |
| 593 | switch n.typ { |
| 594 | case ntStatic: |
| 595 | idx = longestPrefix(pattern, n.prefix) |
| 596 | if idx < len(n.prefix) { |
| 597 | continue |
| 598 | } |
| 599 | |
| 600 | case ntParam, ntRegexp: |
| 601 | idx = strings.IndexByte(pattern, '}') + 1 |
| 602 | |
| 603 | case ntCatchAll: |
| 604 | idx = longestPrefix(pattern, "*") |
| 605 | |
| 606 | default: |
| 607 | panic("chi: unknown node type") |
| 608 | } |
| 609 | |
| 610 | xpattern = pattern[idx:] |
| 611 | if len(xpattern) == 0 { |
| 612 | return true |
| 613 | } |
| 614 | |
| 615 | return n.findPattern(xpattern) |
| 616 | } |
| 617 | return false |
| 618 | } |
| 619 | |
| 620 | func (n *node) routes() []Route { |
| 621 | rts := []Route{} |