diff options
Diffstat (limited to 'view/recipe.go')
-rw-r--r-- | view/recipe.go | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/view/recipe.go b/view/recipe.go index 1dd6045..25abc6b 100644 --- a/view/recipe.go +++ b/view/recipe.go @@ -18,13 +18,32 @@ func Recipe(w http.ResponseWriter, r *http.Request) { return } - tmpl := "recipe" - edit, ok := r.URL.Query()["edit"] - if ok && len(edit) == 1 && edit[0] == "true" { - tmpl = "recipe-edit" + template := "recipe" + view, ok := r.URL.Query()["view"] + if ok { + if len(view) > 1 { + http.Error(w, "More than one 'view' parameter given in URL", http.StatusBadRequest) + return + } + template = view[0] } - err = html.ExecuteTemplate(w, tmpl, recipe) + is_valid := false + valid_templates := []string{ + "recipe", + "recipe-edit", + } + for _, v := range valid_templates { + if template == v { + is_valid = true + } + } + if !is_valid { + http.Error(w, "Unsupported view: " + template, http.StatusBadRequest) + return + } + + err = html.ExecuteTemplate(w, template, recipe) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return |