ch4.7
This commit is contained in:
@@ -43,5 +43,14 @@ func (app *application) snippetCreate(w http.ResponseWriter, r *http.Request) {
|
||||
app.clientError(w, http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
w.Write([]byte("Create a new snippet"))
|
||||
title := "0 snail"
|
||||
content := "0 snail\nClimb Mount Fuji,\nBut slowly, slowly!\n\n-Kobayshi Issa"
|
||||
expires := 7
|
||||
|
||||
id, err := app.snippets.Insert(title, content, expires)
|
||||
if err != nil {
|
||||
app.serverError(w, err)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/snippet/view?id=%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user