Files
tuu/route.go
2018-03-12 10:08:30 +00:00

34 lines
536 B
Go

package tuu
import (
"net/http"
gcontext "github.com/gorilla/context"
)
type Route struct {
Method string
Path string
Handler Handler
Env string
Middleware MiddlewareStack
}
func (r *Route) ServeHTTP(res http.ResponseWriter, req *http.Request) {
defer gcontext.Clear(req)
c := newContext(*r, res, req)
err := r.Middleware.handler(r)(c)
if err != nil {
c.Response().WriteHeader(500)
c.Response().Write([]byte(err.Error()))
}
}
type StaticRoute struct {
Path string
Handler http.Handler
}