move middleware to its own file

in anticipation of maybe adding more
This commit is contained in:
Lilian Jónsdóttir 2024-01-24 23:33:08 -08:00
parent df3adcde91
commit 108ba4d8c2
2 changed files with 15 additions and 2 deletions

12
cmd/web/middleware.go Normal file
View file

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

View file

@ -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")