in go-rest-demo/cmd/gorilla/main.go [90:112]
func (h *RecipesHandler) GetRecipe(w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"]
recipe, err := h.store.Get(id)
if err != nil {
if err == recipes.NotFoundErr {
NotFoundHandler(w, r)
return
}
InternalServerErrorHandler(w, r)
return
}
jsonBytes, err := json.Marshal(recipe)
if err != nil {
InternalServerErrorHandler(w, r)
return
}
w.WriteHeader(http.StatusOK)
w.Write(jsonBytes)
}