mirror of
https://github.com/cubixle/tuu.git
synced 2026-04-24 18:34:46 +01:00
41 lines
717 B
Go
41 lines
717 B
Go
package tuu
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/sessions"
|
|
|
|
gcontext "github.com/gorilla/context"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type Route struct {
|
|
Method string
|
|
Path string
|
|
Handler Handler
|
|
Env string
|
|
Middleware MiddlewareStack
|
|
Logger *logrus.Logger
|
|
Session sessions.Store
|
|
SessionName string
|
|
}
|
|
|
|
func (r *Route) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
|
defer gcontext.Clear(req)
|
|
|
|
c := newContext(*r, res, req)
|
|
defer c.Flash().persist(c.Session())
|
|
|
|
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
|
|
}
|