ch4.7
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"gitea.local.lab/Lbenedar/snippetbox/internal/models"
|
||||
)
|
||||
|
||||
func (app *application) home(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -34,7 +37,17 @@ func (app *application) snippetView(w http.ResponseWriter, r *http.Request) {
|
||||
app.notFound(w)
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, "Display a specific snippet with ID %d...", id)
|
||||
|
||||
snippet, err := app.snippets.Get(id)
|
||||
if err != nil {
|
||||
if errors.Is(err, models.ErrNoRecord) {
|
||||
app.notFound(w)
|
||||
} else {
|
||||
app.serverError(w, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, "%+v", snippet)
|
||||
}
|
||||
|
||||
func (app *application) snippetCreate(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user