Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexedwards/fa02ec95402f687e5f08f54a575a55c7 to your computer and use it in GitHub Desktop.
Save alexedwards/fa02ec95402f687e5f08f54a575a55c7 to your computer and use it in GitHub Desktop.
example.go
func (app *application) showMovieHandler(w http.ResponseWriter, r *http.Request) {
id, err := app.readIDParam(r)
if err != nil {
// IT'S THIS LINE HERE THAT YOU NEED TO CHANGE to use the new notFoundResponse() helper.
app.notFoundResponse(w, r)
return
}
movie := data.Movie{
ID: id,
CreatedAt: time.Now(),
Title: "Casablanca",
Runtime: 102,
Genres: []string{"drama", "romance", "war"},
Version: 1,
}
err = app.writeJSON(w, http.StatusOK, envelope{"movie": movie}, nil)
if err != nil {
app.serverErrorResponse(w, r, err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment