MCPcopy Create free account
hub / github.com/couchbase/cbft / ServeHTTP

Method ServeHTTP

http/doc_count.go:27–55  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

25}
26
27func (h *DocCountHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
28 // find the index to operate on
29 var indexName string
30 if h.IndexNameLookup != nil {
31 indexName = h.IndexNameLookup(req)
32 }
33 if indexName == "" {
34 indexName = h.defaultIndexName
35 }
36 index := IndexByName(indexName)
37 if index == nil {
38 showError(w, req, fmt.Sprintf("no such index '%s'", indexName), 404)
39 return
40 }
41
42 docCount, err := index.DocCount()
43 if err != nil {
44 showError(w, req, fmt.Sprintf("error counting docs: %v", err), 500)
45 return
46 }
47 rv := struct {
48 Status string `json:"status"`
49 Count uint64 `json:"count"`
50 }{
51 Status: "ok",
52 Count: docCount,
53 }
54 mustEncode(w, rv)
55}

Callers

nothing calls this directly

Calls 4

IndexByNameFunction · 0.85
showErrorFunction · 0.85
mustEncodeFunction · 0.70
DocCountMethod · 0.65

Tested by

no test coverage detected