// WriteRenderedHTML - Writes rendered component from context to response writer. func WriteRenderedHTML(ctx context.Context, w http.ResponseWriter, r *http.Request) { res, ok := components.RenderedFromContext(ctx) if !ok { helpers.WriteError(w, r, http.StatusBadRequest, "component not rendered") return } w.Header().Set("Content-Type", "text/html") w.Write([]byte(res.HTML())) }
// WriteRenderedJSON - Writes rendered component from context to response writer. func WriteRenderedJSON(ctx context.Context, w http.ResponseWriter, r *http.Request) { res, ok := components.RenderedFromContext(ctx) if !ok { helpers.WriteError(w, r, http.StatusBadRequest, "component not rendered") return } w.Header().Set("Content-Type", "application/json") if err := json.NewEncoder(w).Encode(res); err != nil { glog.Warningf("[api] response encode error: %v", err) } }