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

Method ServeHTTP

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

Source from the content-addressed store, hash-verified

25}
26
27func (h *ListFieldsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
28
29 // find the index to operate on
30 var indexName string
31 if h.IndexNameLookup != nil {
32 indexName = h.IndexNameLookup(req)
33 }
34 if indexName == "" {
35 indexName = h.defaultIndexName
36 }
37 index := IndexByName(indexName)
38 if index == nil {
39 showError(w, req, fmt.Sprintf("no such index '%s'", indexName), 404)
40 return
41 }
42
43 fields, err := index.Fields()
44 if err != nil {
45 showError(w, req, fmt.Sprintf("error: %v", err), 500)
46 return
47 }
48
49 fieldsResponse := struct {
50 Fields []string `json:"fields"`
51 }{
52 Fields: fields,
53 }
54
55 // encode the response
56 mustEncode(w, fieldsResponse)
57}

Callers

nothing calls this directly

Calls 4

IndexByNameFunction · 0.85
showErrorFunction · 0.85
mustEncodeFunction · 0.70
FieldsMethod · 0.45

Tested by

no test coverage detected