|
1 |
| -// The router matches incoming requests by the request method and the path. |
2 |
| -// If a handle is registered for this path and method, the router delegates the |
3 |
| -// request to that function. |
4 |
| -// For the methods GET, POST, PUT, PATCH and DELETE shortcut functions exist to |
5 |
| -// register handles, for all other methods router.Handle can be used. |
6 |
| -// |
7 |
| -// The registered path, against which the router matches incoming requests, can |
8 |
| -// contain two types of parameters: |
9 |
| -// Syntax Type |
10 |
| -// :name named parameter |
11 |
| -// *name catch-all parameter |
12 |
| -// |
13 |
| -// Named parameters are dynamic path segments. They match anything until the |
14 |
| -// next '/' or the path end: |
15 |
| -// Path: /blog/:category/:post |
16 |
| -// |
17 |
| -// Requests: |
18 |
| -// /blog/go/request-routers match: category="go", post="request-routers" |
19 |
| -// /blog/go/request-routers/ no match, but the router would redirect |
20 |
| -// /blog/go/ no match |
21 |
| -// /blog/go/request-routers/comments no match |
22 |
| -// |
23 |
| -// Catch-all parameters match anything until the path end, including the |
24 |
| -// directory index (the '/' before the catch-all). Since they match anything |
25 |
| -// until the end, catch-all parameters must always be the final path element. |
26 |
| -// Path: /files/*filepath |
27 |
| -// |
28 |
| -// Requests: |
29 |
| -// /files/ match: filepath="/" |
30 |
| -// /files/LICENSE match: filepath="/LICENSE" |
31 |
| -// /files/templates/article.html match: filepath="/templates/article.html" |
32 |
| -// /files no match, but the router would redirect |
33 |
| -// |
34 |
| -// The value of parameters is saved as a slice of the Param struct, consisting |
35 |
| -// each of a key and a value. The slice is passed to the Handle func as a third |
36 |
| -// parameter. |
37 |
| -// There are two ways to retrieve the value of a parameter: |
38 |
| -// // by the name of the parameter |
39 |
| -// user := ps.ByName("user") // defined by :user or *user |
40 |
| -// |
41 |
| -// // by the index of the parameter. This way you can also get the name (key) |
42 |
| -// thirdKey := ps[2].Key // the name of the 3rd parameter |
43 |
| -// thirdValue := ps[2].Value // the value of the 3rd parameter |
| 1 | +// Copyright 2013 Julien Schmidt. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be found |
| 3 | +// in the LICENSE file. |
44 | 4 |
|
45 | 5 | package faygo
|
46 | 6 |
|
@@ -140,9 +100,7 @@ func (n *node) incrementChildPrio(pos int) int {
|
140 | 100 | newPos := pos
|
141 | 101 | for newPos > 0 && n.children[newPos-1].priority < prio {
|
142 | 102 | // swap node positions
|
143 |
| - tmpN := n.children[newPos-1] |
144 |
| - n.children[newPos-1] = n.children[newPos] |
145 |
| - n.children[newPos] = tmpN |
| 103 | + n.children[newPos-1], n.children[newPos] = n.children[newPos], n.children[newPos-1] |
146 | 104 |
|
147 | 105 | newPos--
|
148 | 106 | }
|
@@ -230,7 +188,12 @@ func (n *node) addRoute(path string, handle Handle) {
|
230 | 188 | continue walk
|
231 | 189 | } else {
|
232 | 190 | // Wildcard conflict
|
233 |
| - pathSeg := strings.SplitN(path, "/", 2)[0] |
| 191 | + var pathSeg string |
| 192 | + if n.nType == catchAll { |
| 193 | + pathSeg = path |
| 194 | + } else { |
| 195 | + pathSeg = strings.SplitN(path, "/", 2)[0] |
| 196 | + } |
234 | 197 | prefix := fullPath[:strings.Index(fullPath, pathSeg)] + n.path
|
235 | 198 | panic("'" + pathSeg +
|
236 | 199 | "' in new path '" + fullPath +
|
|
0 commit comments