diff --git a/cmd/web/middleware.go b/cmd/web/middleware.go new file mode 100644 index 0000000..da6d15b --- /dev/null +++ b/cmd/web/middleware.go @@ -0,0 +1,12 @@ +package main + +import ( + "net/http" + + "github.com/go-chi/chi/v5/middleware" +) + +// Middleware is a slice of Middleware (aka func(n http.Handler) http.Handler {}) +var Middleware []func(next http.Handler) http.Handler = []func(next http.Handler) http.Handler{ + middleware.Recoverer, +} diff --git a/cmd/web/routes.go b/cmd/web/routes.go index 7feb5d6..581fe08 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/go-chi/chi/v5" - "github.com/go-chi/chi/v5/middleware" "git.burning.moe/celediel/burning.moe/internal/config" "git.burning.moe/celediel/burning.moe/internal/handlers" @@ -16,7 +15,9 @@ func routes(app *config.AppConfig) http.Handler { mux := chi.NewRouter() // Import some middleware - mux.Use(middleware.Recoverer) + for _, mw := range Middleware { + mux.Use(mw) + } // Setup static file server app.Logger.Debug("Setting up /static file server")