summaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-10-23 20:34:57 +0200
committerxengineering <me@xengineering.eu>2024-10-23 20:34:57 +0200
commite66691083a2455c29b50a2970c0aba1d6afca753 (patch)
tree1f3192351038693b5fc219148fbc39cf2e869a87 /server.go
parent9d14fee31507551149dcdf31c59798624330f3f3 (diff)
downloadceres-e66691083a2455c29b50a2970c0aba1d6afca753.tar
ceres-e66691083a2455c29b50a2970c0aba1d6afca753.tar.zst
ceres-e66691083a2455c29b50a2970c0aba1d6afca753.zip
Switch to http.Handler
The used `func(http.ResponseWriter, *http.Request)` return values made the HTTP handler factory functions quite unreadable. Thus it is switched to the http.Handler type.
Diffstat (limited to 'server.go')
-rw-r--r--server.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/server.go b/server.go
index 35cd44d..3b17227 100644
--- a/server.go
+++ b/server.go
@@ -19,21 +19,24 @@ var static embed.FS
func NewServer(addr string, db *model.DB) *Server {
mux := http.NewServeMux()
- mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.FS(static))))
+ mux.Handle(
+ "GET /static/",
+ http.StripPrefix("/static/", http.FileServer(http.FS(static))),
+ )
- mux.HandleFunc("GET /version", view.VersionRead(version))
+ mux.Handle("GET /version", view.VersionRead(version))
- mux.HandleFunc("GET /recipes", view.RecipesRead(db))
+ mux.Handle("GET /recipes", view.RecipesRead(db))
- mux.HandleFunc("GET /recipe/create", view.RecipeCreate)
- mux.HandleFunc("POST /recipe", controller.RecipeCreate(db))
- mux.HandleFunc("GET /recipe/{id}", view.RecipeRead(db))
- mux.HandleFunc("POST /recipe/{id}", controller.RecipeUpdate(db))
- mux.HandleFunc("DELETE /recipe/{id}", controller.RecipeDelete(db))
+ mux.Handle("GET /recipe/create", view.RecipeCreate())
+ mux.Handle("POST /recipe", controller.RecipeCreate(db))
+ mux.Handle("GET /recipe/{id}", view.RecipeRead(db))
+ mux.Handle("POST /recipe/{id}", controller.RecipeUpdate(db))
+ mux.Handle("DELETE /recipe/{id}", controller.RecipeDelete(db))
- mux.HandleFunc("GET /favicon.ico", view.FaviconRead)
+ mux.Handle("GET /favicon.ico", view.FaviconRead())
- mux.HandleFunc("GET /", view.IndexRead)
+ mux.Handle("GET /", view.IndexRead())
var srv http.Server
srv.Addr = addr