diff options
author | xengineering <me@xengineering.eu> | 2024-10-23 20:34:57 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-10-23 20:34:57 +0200 |
commit | e66691083a2455c29b50a2970c0aba1d6afca753 (patch) | |
tree | 1f3192351038693b5fc219148fbc39cf2e869a87 /view/recipes.go | |
parent | 9d14fee31507551149dcdf31c59798624330f3f3 (diff) | |
download | ceres-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 'view/recipes.go')
-rw-r--r-- | view/recipes.go | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/view/recipes.go b/view/recipes.go index e7153cd..8cd107e 100644 --- a/view/recipes.go +++ b/view/recipes.go @@ -6,21 +6,23 @@ import ( "xengineering.eu/ceres/model" ) -func RecipesRead(db *model.DB) func(http.ResponseWriter, *http.Request) { - return func(w http.ResponseWriter, r *http.Request) { - recipes := make(model.Recipes, 0) +func RecipesRead(db *model.DB) http.Handler { + return http.HandlerFunc( + func(w http.ResponseWriter, r *http.Request) { + recipes := make(model.Recipes, 0) - var obj model.Object = &recipes - err := db.Transaction(obj.Read) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + var obj model.Object = &recipes + err := db.Transaction(obj.Read) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } - err = html.ExecuteTemplate(w, "recipes", recipes) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - } + err = html.ExecuteTemplate(w, "recipes", recipes) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + }, + ) } |