12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package restful
- type curlyRoute struct {
- route Route
- paramCount int
- staticCount int
- }
- type sortableCurlyRoutes []curlyRoute
- func (s *sortableCurlyRoutes) add(route curlyRoute) {
- *s = append(*s, route)
- }
- func (s sortableCurlyRoutes) routes() (routes []Route) {
- for _, each := range s {
- routes = append(routes, each.route)
- }
- return routes
- }
- func (s sortableCurlyRoutes) Len() int {
- return len(s)
- }
- func (s sortableCurlyRoutes) Swap(i, j int) {
- s[i], s[j] = s[j], s[i]
- }
- func (s sortableCurlyRoutes) Less(i, j int) bool {
- ci := s[i]
- cj := s[j]
-
- if ci.staticCount < cj.staticCount {
- return true
- }
- if ci.staticCount > cj.staticCount {
- return false
- }
-
- if ci.paramCount < cj.paramCount {
- return true
- }
- if ci.paramCount > cj.paramCount {
- return false
- }
- return ci.route.Path < cj.route.Path
- }
|