Created
June 8, 2021 16:42
-
-
Save alexedwards/fa02ec95402f687e5f08f54a575a55c7 to your computer and use it in GitHub Desktop.
example.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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