MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / handleDump

Method handleDump

rest/bulk_api.go:279–309  ·  view source on GitHub ↗

HTTP handler for _dump

()

Source from the content-addressed store, hash-verified

277
278// HTTP handler for _dump
279func (h *handler) handleDump() error {
280 viewName := h.PathVar("view")
281 base.InfofCtx(h.ctx(), base.KeyHTTP, "Dump view %q", base.MD(viewName))
282 opts := db.Body{"stale": false, "reduce": false}
283 vs, ok := h.db.Bucket.(sgbucket.ViewStore)
284 if !ok {
285 return base.HTTPErrorf(http.StatusInternalServerError, "bucket does not support views")
286 }
287 result, err := vs.View(h.ctx(), db.DesignDocSyncGateway(), viewName, opts)
288 if err != nil {
289 return err
290 }
291 title := fmt.Sprintf("/%s: “%s” View", html.EscapeString(h.db.Name), html.EscapeString(viewName))
292 h.setHeader("Content-Type", `text/html; charset="UTF-8"`)
293 _, _ = h.response.Write([]byte(fmt.Sprintf(
294 `<!DOCTYPE html><html><head><title>%s</title></head><body>
295 <h1>%s</h1><code>
296 <table border=1>
297 `,
298 title, title)))
299 _, _ = h.response.Write([]byte("\t<tr><th>Key</th><th>Value</th><th>ID</th></tr>\n"))
300 for _, row := range result.Rows {
301 key, _ := base.JSONMarshal(row.Key)
302 value, _ := base.JSONMarshal(row.Value)
303 _, _ = h.response.Write([]byte(fmt.Sprintf("\t<tr><td>%s</td><td>%s</td><td><em>%s</em></td>",
304 html.EscapeString(string(key)), html.EscapeString(string(value)), html.EscapeString(row.ID))))
305 _, _ = h.response.Write([]byte("</tr>\n"))
306 }
307 _, _ = h.response.Write([]byte("</table>\n</code></html></body>"))
308 return nil
309}
310
311// HTTP handler for _repair
312func (h *handler) handleRepair() error {

Callers

nothing calls this directly

Calls 10

PathVarMethod · 0.95
ctxMethod · 0.95
setHeaderMethod · 0.95
InfofCtxFunction · 0.92
MDFunction · 0.92
HTTPErrorfFunction · 0.92
DesignDocSyncGatewayFunction · 0.92
JSONMarshalFunction · 0.92
ViewMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected