traefik/middlewares/routes.go

29 lines
607 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/gorilla/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) {
2015-09-12 17:22:44 +00:00
json, _ := json.Marshal(routeMatch.Handler)
log.Println("Request match route ", json)
}
next(rw, r)
}