Add routes priorities

Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
Emile Vauge 2016-06-03 17:58:33 +02:00
parent 7cdd062432
commit 208998972a
No known key found for this signature in database
GPG key ID: D808B4C167352E59
9 changed files with 24 additions and 15 deletions

View file

@ -20,6 +20,7 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/negroni"
"github.com/containous/mux"
"github.com/containous/oxy/cbreaker"
"github.com/containous/oxy/connlimit"
"github.com/containous/oxy/forward"
@ -30,7 +31,6 @@ import (
"github.com/containous/traefik/provider"
"github.com/containous/traefik/safe"
"github.com/containous/traefik/types"
"github.com/gorilla/mux"
"github.com/mailgun/manners"
"github.com/streamrail/concurrent-map"
)
@ -501,6 +501,9 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
} else {
log.Debugf("Reusing backend %s", frontend.Backend)
}
if frontend.Priority > 0 {
newServerRoute.route.Priority(frontend.Priority)
}
server.wireFrontendBackend(newServerRoute, backends[frontend.Backend])
}
err := newServerRoute.route.GetError()
@ -511,6 +514,10 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
}
}
middlewares.SetBackend2FrontendMap(&backend2FrontendMap)
//sort routes
for _, serverEntryPoint := range serverEntryPoints {
serverEntryPoint.httpRouter.GetHandler().SortRoutes()
}
return serverEntryPoints, nil
}
@ -576,6 +583,7 @@ func getRoute(serverRoute *serverRoute, route *types.Route) error {
if err != nil {
return err
}
newRoute.Priority(serverRoute.route.GetPriority() + len(route.Rule))
serverRoute.route = newRoute
return nil
}