GetArticle returns the specific Article. You'll notice it just fetches the Article right off the context, as its understood that if we made it this far, the Article must be on the context. In case its not due to a bug, then it will panic, and our Recoverer will save us.
(w http.ResponseWriter, r *http.Request)
| 171 | // if we made it this far, the Article must be on the context. In case |
| 172 | // its not due to a bug, then it will panic, and our Recoverer will save us. |
| 173 | func GetArticle(w http.ResponseWriter, r *http.Request) { |
| 174 | // Assume if we've reach this far, we can access the article |
| 175 | // context because this handler is a child of the ArticleCtx |
| 176 | // middleware. The worst case, the recoverer middleware will save us. |
| 177 | article := r.Context().Value("article").(*Article) |
| 178 | |
| 179 | if err := render.Render(w, r, NewArticleResponse(article)); err != nil { |
| 180 | render.Render(w, r, ErrRender(err)) |
| 181 | return |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // UpdateArticle updates an existing Article in our persistent store. |
| 186 | func UpdateArticle(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected