HTTP handler for _dump
()
| 277 | |
| 278 | // HTTP handler for _dump |
| 279 | func (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 |
| 312 | func (h *handler) handleRepair() error { |
nothing calls this directly
no test coverage detected