2015-09-12 17:22:44 +00:00
|
|
|
package middlewares
|
|
|
|
|
|
|
|
import (
|
2015-09-15 20:32:09 +00:00
|
|
|
"encoding/json"
|
2015-09-12 17:22:44 +00:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2015-09-24 15:16:13 +00:00
|
|
|
|
2016-06-03 15:58:33 +00:00
|
|
|
"github.com/containous/mux"
|
2015-09-12 17:22:44 +00:00
|
|
|
)
|
|
|
|
|
2015-11-01 18:34:54 +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
|
|
|
|
}
|
|
|
|
|
2015-11-01 18:34:54 +00:00
|
|
|
// 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) {
|
2015-09-15 20:32:09 +00:00
|
|
|
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)
|
|
|
|
}
|