burning.moe/cmd/web/routes.go
Lilian Jónsdóttir a7f6bb35e7 it works!
initial build that basically replicates my old HTML site
2024-01-22 20:10:14 -08:00

32 lines
853 B
Go

package main
import (
"net/http"
"git.burning.moe/celediel/burning.moe/internal/config"
"git.burning.moe/celediel/burning.moe/internal/handlers"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
// routes handles all of the HTTP setup. Middleware is enabled,
// static fileserver is setup, and handlers are ... handled
func routes(app *config.AppConfig) http.Handler {
mux := chi.NewRouter()
// Import some middleware
mux.Use(middleware.Recoverer)
// Setup static file server
app.Logger.Debug("Setting up /static file server")
mux.Handle("/static/*", http.StripPrefix("/static", http.FileServer(http.Dir("./static"))))
// Setup routes for handlers
for _, handler := range handlers.Handlers {
app.Logger.Info("Setting up handler for " + handler.Handles)
mux.Get(handler.Handles, handler.Handler)
}
return mux
}