ch7.2
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"gitea.local.lab/Lbenedar/snippetbox/internal/models"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
func (app *application) render(w http.ResponseWriter, status int, page string, data *templateData) {
|
||||
@@ -46,7 +47,8 @@ func (app *application) home(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (app *application) snippetView(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.Atoi(r.URL.Query().Get("id"))
|
||||
params := httprouter.ParamsFromContext(r.Context())
|
||||
id, err := strconv.Atoi(params.ByName("id"))
|
||||
if err != nil || id < 1 {
|
||||
app.notFound(w)
|
||||
return
|
||||
@@ -68,11 +70,10 @@ func (app *application) snippetView(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (app *application) snippetCreate(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
w.Header().Set("Allow", http.MethodPost)
|
||||
app.clientError(w, http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
w.Write([]byte("Display the form for creating a new snippet..."))
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user