Files
schreifuchs.ch/internal/server/routes.go
T
2026-03-02 22:36:47 +01:00

34 lines
752 B
Go

package server
import (
"log/slog"
"net/http"
"time"
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/handler"
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web"
)
func (s *Server) RegisterRoutes() http.Handler {
mux := http.NewServeMux()
fileServer := http.FileServer(http.FS(web.GetStaticFS()))
mux.Handle("/static/", http.StripPrefix("/static/", fileServer))
mux.Handle("/", handler.Home())
return s.loggingMiddleware(mux)
}
func (s *Server) loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
next.ServeHTTP(w, r)
slog.Info("request",
"method", r.Method,
"path", r.URL.Path,
"duration", time.Since(start),
)
})
}