Newer
Older
import (
"context"
"net/http"
"time"
)
type appHandler struct {
app *App
f func(app *App, ctx context.Context, w http.ResponseWriter, r *http.Request)
}
func (h *appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
h.f(h.app, ctx, w, r)
}
func NewAppHandler(app *App, f func(app *App, ctx context.Context, w http.ResponseWriter, r *http.Request)) http.Handler {
return &appHandler{app: app, f: f}
}