in go-rest-demo/cmd/standardlib/main.go [127:153]
func (h *RecipesHandler) GetRecipe(w http.ResponseWriter, r *http.Request) {
matches := RecipeReWithID.FindStringSubmatch(r.URL.Path)
if len(matches) < 2 {
InternalServerErrorHandler(w, r)
return
}
recipe, err := h.store.Get(matches[1])
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)
}