MCPcopy
hub / github.com/go-chi/chi / GetArticle

Function GetArticle

_examples/rest/main.go:173–183  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
173func 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.
186func UpdateArticle(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 4

ErrRenderFunction · 0.85
ValueMethod · 0.80
NewArticleResponseFunction · 0.70
RenderMethod · 0.45

Tested by

no test coverage detected