Skip to content

Commit

Permalink
Add a convenience method to add method to routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Piszmog committed Jan 6, 2025
1 parent 7777d15 commit 9cc8524
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions server/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 9cc8524

Please sign in to comment.