Skip to content

Commit 9cc8524

Browse files
committed
Add a convenience method to add method to routes
1 parent 7777d15 commit 9cc8524

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

server/router/router.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ func New(logger *slog.Logger, database db.Database) http.Handler {
1717

1818
mux := http.NewServeMux()
1919

20-
mux.Handle("/assets/", middleware.CacheMiddleware(http.FileServer(http.FS(dist.AssetsDir))))
21-
mux.HandleFunc("/", h.Home)
20+
mux.Handle(newPath(http.MethodGet, "/assets/"), middleware.CacheMiddleware(http.FileServer(http.FS(dist.AssetsDir))))
21+
mux.HandleFunc(newPath(http.MethodGet, "/"), h.Home)
2222

2323
return middleware.NewLoggingMiddleware(logger, mux)
2424
}
25+
26+
func newPath(method string, path string) string {
27+
return method + " " + path
28+
}

0 commit comments

Comments
 (0)