ch8.1
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user