From 9cc8524cf2585483b84f3e4301db2d79ec23f5a7 Mon Sep 17 00:00:00 2001 From: Randell Date: Mon, 6 Jan 2025 15:46:18 -0700 Subject: [PATCH] Add a convenience method to add method to routes --- server/router/router.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/router/router.go b/server/router/router.go index 7e5ce57..8df8703 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -17,8 +17,12 @@ func New(logger *slog.Logger, database db.Database) http.Handler { mux := http.NewServeMux() - mux.Handle("/assets/", middleware.CacheMiddleware(http.FileServer(http.FS(dist.AssetsDir)))) - mux.HandleFunc("/", h.Home) + mux.Handle(newPath(http.MethodGet, "/assets/"), middleware.CacheMiddleware(http.FileServer(http.FS(dist.AssetsDir)))) + mux.HandleFunc(newPath(http.MethodGet, "/"), h.Home) return middleware.NewLoggingMiddleware(logger, mux) } + +func newPath(method string, path string) string { + return method + " " + path +}