2015-09-12 17:22:44 +00:00
|
|
|
/*
|
|
|
|
Copyright
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2015-09-12 17:22:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Routes struct {
|
|
|
|
router *mux.Router
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2015-09-12 17:22:44 +00:00
|
|
|
json, _ := json.Marshal(routeMatch.Handler)
|
|
|
|
log.Println("Request match route ", json)
|
|
|
|
}
|
|
|
|
next(rw, r)
|
|
|
|
}
|