File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import (
11
11
"net/http"
12
12
"path"
13
13
"regexp"
14
+ "sort"
14
15
)
15
16
16
17
var (
@@ -403,6 +404,17 @@ func (r *Router) walk(walkFn WalkFunc, ancestors []*Route) error {
403
404
return nil
404
405
}
405
406
407
+ type routes []* Route
408
+
409
+ func (r routes ) Len () int { return len (r ) }
410
+ func (r routes ) Swap (i , j int ) { r [i ], r [j ] = r [j ], r [i ] }
411
+ func (r routes ) Less (i , j int ) bool { return r [i ].GetPriority () > r [j ].GetPriority () }
412
+
413
+ // SortRoutes sort routes by route priority
414
+ func (r * Router ) SortRoutes () {
415
+ sort .Sort (routes (r .routes ))
416
+ }
417
+
406
418
// ----------------------------------------------------------------------------
407
419
// Context
408
420
// ----------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ type Route struct {
23
23
name string
24
24
// Error resulted from building a route.
25
25
err error
26
+ // Priority of this route
27
+ priority int
26
28
27
29
// "global" reference to all named routes
28
30
namedRoutes map [string ]* Route
@@ -153,6 +155,19 @@ func (r *Route) GetName() string {
153
155
return r .name
154
156
}
155
157
158
+ // Priority -----------------------------------------------------------------------
159
+
160
+ // Priority sets the priority for the route
161
+ func (r * Route ) Priority (priority int ) * Route {
162
+ r .priority = priority
163
+ return r
164
+ }
165
+
166
+ // GetPriority returns the priority for the route.
167
+ func (r * Route ) GetPriority () int {
168
+ return r .priority
169
+ }
170
+
156
171
// ----------------------------------------------------------------------------
157
172
// Matchers
158
173
// ----------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments