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) {
|
func (app *application) snippetCreatePost(w http.ResponseWriter, r *http.Request) {
|
||||||
title := "0 snail"
|
err := r.ParseForm()
|
||||||
content := "0 snail\nClimb Mount Fuji,\nBut slowly, slowly!\n\n-Kobayshi Issa"
|
if err != nil {
|
||||||
expires := 7
|
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)
|
id, err := app.snippets.Insert(title, content, expires)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.serverError(w, err)
|
app.serverError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
http.Redirect(w, r, fmt.Sprintf("/snippet/view/%d", id), http.StatusSeeOther)
|
http.Redirect(w, r, fmt.Sprintf("/snippet/view/%d", id), http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user