traefik/middlewares/routes.go

29 lines
606 B
Go
Raw Normal View History

2015-09-12 17:22:44 +00:00
package middlewares
import (
"encoding/json"
2015-09-12 17:22:44 +00:00
"log"
"net/http"
"github.com/containous/mux"
2015-09-12 17:22:44 +00:00
)
// Routes holds the gorilla mux routes (for the API & co).
2015-09-12 17:22:44 +00:00
type Routes struct {
router *mux.Router
}
// NewRoutes return a Routes based on the given router.
2015-09-12 17:22:44 +00:00
func NewRoutes(router *mux.Router) *Routes {
return &Routes{router}
}
func (router *Routes) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
routeMatch := mux.RouteMatch{}
if router.router.Match(r, &routeMatch) {
2018-07-03 08:02:03 +00:00
rt, _ := json.Marshal(routeMatch.Handler)
log.Println("Request match route ", rt)
2015-09-12 17:22:44 +00:00
}
next(rw, r)
}