mirror of
https://github.com/cubixle/tuu.git
synced 2026-04-24 21:24:43 +01:00
quick implementation of middleware
This commit is contained in:
10
route.go
10
route.go
@@ -3,8 +3,6 @@ package tuu
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
gcontext "github.com/gorilla/context"
|
||||
)
|
||||
|
||||
@@ -12,16 +10,18 @@ type Route struct {
|
||||
Method string
|
||||
Path string
|
||||
Handler Handler
|
||||
MuxHandler mux.Route
|
||||
Env string
|
||||
Middleware MiddlewareStack
|
||||
}
|
||||
|
||||
func (r *Route) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
||||
defer gcontext.Clear(req)
|
||||
|
||||
c := NewContext(*r, res, req, r.Env)
|
||||
c := newContext(*r, res, req)
|
||||
|
||||
if err := r.Handler(c); err != nil {
|
||||
err := r.Middleware.handler(r)(c)
|
||||
|
||||
if err != nil {
|
||||
c.Response().WriteHeader(500)
|
||||
c.Response().Write([]byte(err.Error()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user