Skip to content
app_handler.go 528 B
Newer Older
Lo^2's avatar
Lo^2 committed
package server
Lo^2's avatar
wip
Lo^2 committed

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}
}