3 // Copyright 2013 Ernest Micklei. All rights reserved.
4 // Use of this source code is governed by a license
5 // that can be found in the LICENSE file.
7 // curlyRoute exits for sorting Routes by the CurlyRouter based on number of parameters and number of static path elements.
8 type curlyRoute struct {
14 // sortableCurlyRoutes orders by most parameters and path elements first.
15 type sortableCurlyRoutes []curlyRoute
17 func (s *sortableCurlyRoutes) add(route curlyRoute) {
18 *s = append(*s, route)
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) // TODO change return type
29 func (s sortableCurlyRoutes) Len() int {
32 func (s sortableCurlyRoutes) Swap(i, j int) {
33 s[i], s[j] = s[j], s[i]
35 func (s sortableCurlyRoutes) Less(i, j int) bool {
40 if a.staticCount < b.staticCount {
43 if a.staticCount > b.staticCount {
47 if a.paramCount < b.paramCount {
50 if a.paramCount > b.paramCount {
53 return a.route.Path < b.route.Path