...
1 package restful
2
3
4
5
6
7
8 type curlyRoute struct {
9 route Route
10 paramCount int
11 staticCount int
12 }
13
14
15 type sortableCurlyRoutes []curlyRoute
16
17 func (s *sortableCurlyRoutes) add(route curlyRoute) {
18 *s = append(*s, route)
19 }
20
21 func (s sortableCurlyRoutes) routes() (routes []Route) {
22 routes = make([]Route, 0, len(s))
23 for _, each := range s {
24 routes = append(routes, each.route)
25 }
26 return routes
27 }
28
29 func (s sortableCurlyRoutes) Len() int {
30 return len(s)
31 }
32 func (s sortableCurlyRoutes) Swap(i, j int) {
33 s[i], s[j] = s[j], s[i]
34 }
35 func (s sortableCurlyRoutes) Less(i, j int) bool {
36 a := s[j]
37 b := s[i]
38
39
40 if a.staticCount < b.staticCount {
41 return true
42 }
43 if a.staticCount > b.staticCount {
44 return false
45 }
46
47 if a.paramCount < b.paramCount {
48 return true
49 }
50 if a.paramCount > b.paramCount {
51 return false
52 }
53 return a.route.Path < b.route.Path
54 }
55
View as plain text