(w http.ResponseWriter, req *http.Request)
| 25 | } |
| 26 | |
| 27 | func (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 | } |
nothing calls this directly
no test coverage detected