File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
10
10
"net/http"
11
11
"path"
12
12
"regexp"
13
+ "sort"
13
14
14
15
"github.com/gorilla/context"
15
16
)
@@ -305,6 +306,17 @@ func (r *Router) walk(walkFn WalkFunc, ancestors []*Route) error {
305
306
return nil
306
307
}
307
308
309
+ type routes []* Route
310
+
311
+ func (r routes ) Len () int { return len (r ) }
312
+ func (r routes ) Swap (i , j int ) { r [i ], r [j ] = r [j ], r [i ] }
313
+ func (r routes ) Less (i , j int ) bool { return r [i ].GetPriority () > r [j ].GetPriority () }
314
+
315
+ // SortRoutes sort routes by route priority
316
+ func (r * Router ) SortRoutes () {
317
+ sort .Sort (routes (r .routes ))
318
+ }
319
+
308
320
// ----------------------------------------------------------------------------
309
321
// Context
310
322
// ----------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ type Route struct {
35
35
name string
36
36
// Error resulted from building a route.
37
37
err error
38
+ // Priority of this route
39
+ priority int
38
40
39
41
buildVarsFunc BuildVarsFunc
40
42
}
@@ -127,6 +129,19 @@ func (r *Route) GetName() string {
127
129
return r .name
128
130
}
129
131
132
+ // Priority -----------------------------------------------------------------------
133
+
134
+ // Priority sets the priority for the route
135
+ func (r * Route ) Priority (priority int ) * Route {
136
+ r .priority = priority
137
+ return r
138
+ }
139
+
140
+ // GetPriority returns the priority for the route.
141
+ func (r * Route ) GetPriority () int {
142
+ return r .priority
143
+ }
144
+
130
145
// ----------------------------------------------------------------------------
131
146
// Matchers
132
147
// ----------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments