package web import "net/http" // HandlerFunc is our handler signature type HandlerFunc func(e *Env, w http.ResponseWriter, r *http.Request) error // The Handler struct that takes a configured Env and a function matching our // handler signature type Handler struct { *Env H HandlerFunc } // ServeHTTP allows our Handler type to satisfy http.Handler. func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { err := h.H(h.Env, w, r) if err != nil { // Any error types we don't specifically look out for default // to serving a HTTP 500 h.Env.Log.Errorf(err.Error()) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) } }