From b8fad1a63f7ce01f1b441af64d9929e34345d262 Mon Sep 17 00:00:00 2001 From: lbenedar Date: Thu, 5 Mar 2026 15:08:06 +0300 Subject: [PATCH] ch8.1 --- cmd/web/handlers.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index bb223e6..61a0b66 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -76,14 +76,24 @@ func (app *application) snippetCreate(w http.ResponseWriter, r *http.Request) { } func (app *application) snippetCreatePost(w http.ResponseWriter, r *http.Request) { - title := "0 snail" - content := "0 snail\nClimb Mount Fuji,\nBut slowly, slowly!\n\n-Kobayshi Issa" - expires := 7 + err := r.ParseForm() + if err != nil { + app.clientError(w, http.StatusBadRequest) + return + } + title := r.PostForm.Get("title") + content := r.PostForm.Get("content") + expires, err := strconv.Atoi(r.PostForm.Get("expires")) + if err != nil { + app.clientError(w, http.StatusBadRequest) + return + } id, err := app.snippets.Insert(title, content, expires) if err != nil { app.serverError(w, err) return } + http.Redirect(w, r, fmt.Sprintf("/snippet/view/%d", id), http.StatusSeeOther) }