HTTP handler for GET _design/$ddoc/_view/$view
()
| 73 | |
| 74 | // HTTP handler for GET _design/$ddoc/_view/$view |
| 75 | func (h *handler) handleView() error { |
| 76 | // Couchbase Server view API: |
| 77 | // http://docs.couchbase.com/admin/admin/REST/rest-views-get.html |
| 78 | ddocName := h.PathVar("ddoc") |
| 79 | viewName := h.PathVar("view") |
| 80 | if ddocName == "" { |
| 81 | ddocName = db.DesignDocSyncGateway() |
| 82 | } |
| 83 | opts := db.Body{} |
| 84 | |
| 85 | // Boolean options: |
| 86 | for _, name := range []string{"inclusive_end", "descending", "include_docs", "reduce", "group"} { |
| 87 | if val := h.getQuery(name); "" != val { |
| 88 | opts[name] = (val == "true") |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // Integer options: |
| 93 | for _, name := range []string{"skip", "limit", "group_level"} { |
| 94 | if h.getQuery(name) != "" { |
| 95 | opts[name] = h.getIntQuery(name, 0) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // String options: |
| 100 | for _, name := range []string{"startkey_docid", "endkey_docid", "stale"} { |
| 101 | if val := h.getQuery(name); "" != val { |
| 102 | opts[name] = val |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // JSON options: |
| 107 | for _, name := range []string{"startkey", "endkey", "key", "keys"} { |
| 108 | if rawVal := h.getQuery(name); "" != rawVal { |
| 109 | var val interface{} |
| 110 | if err := base.JSONUnmarshal([]byte(rawVal), &val); err != nil { |
| 111 | return err |
| 112 | } |
| 113 | opts[name] = val |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | base.InfofCtx(h.ctx(), base.KeyHTTP, "JSON view %q/%q - opts %v", base.MD(ddocName), base.MD(viewName), base.MD(opts)) |
| 118 | |
| 119 | result, err := h.db.QueryDesignDoc(h.ctx(), ddocName, viewName, opts) |
| 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | h.setHeader("Content-Type", `application/json; charset="UTF-8"`) |
| 124 | h.writeJSON(result) |
| 125 | return nil |
| 126 | } |
nothing calls this directly
no test coverage detected