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

Method ServeHTTP

http/debug.go:32–94  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

30}
31
32func (h *DebugDocumentHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
33
34 // find the index to operate on
35 var indexName string
36 if h.IndexNameLookup != nil {
37 indexName = h.IndexNameLookup(req)
38 }
39 if indexName == "" {
40 indexName = h.defaultIndexName
41 }
42 index := IndexByName(indexName)
43 if index == nil {
44 showError(w, req, fmt.Sprintf("no such index '%s'", indexName), 404)
45 return
46 }
47
48 // find the docID
49 var docID string
50 if h.DocIDLookup != nil {
51 docID = h.DocIDLookup(req)
52 }
53
54 internalIndex, err := index.Advanced()
55 if err != nil {
56 showError(w, req, fmt.Sprintf("error getting index: %v", err), 500)
57 return
58 }
59 internalIndexReader, err := internalIndex.Reader()
60 if err != nil {
61 showError(w, req, fmt.Sprintf("error operning index reader: %v", err), 500)
62 return
63 }
64 upsidedownIndexReader, ok := internalIndexReader.(*upsidedown.IndexReader)
65 if !ok {
66 showError(w, req, "error with index reader", 500)
67 return
68 }
69
70 var rv []interface{}
71 rowChan := upsidedownIndexReader.DumpDoc(docID)
72 for row := range rowChan {
73 switch row := row.(type) {
74 case error:
75 showError(w, req, fmt.Sprintf("error debugging document: %v", row), 500)
76 return
77 case upsidedown.UpsideDownCouchRow:
78 tmp := struct {
79 Key []byte `json:"key"`
80 Val []byte `json:"val"`
81 }{
82 Key: row.Key(),
83 Val: row.Value(),
84 }
85 rv = append(rv, tmp)
86 }
87 }
88 err = internalIndexReader.Close()
89 if err != nil {

Callers

nothing calls this directly

Calls 6

IndexByNameFunction · 0.85
showErrorFunction · 0.85
mustEncodeFunction · 0.70
AdvancedMethod · 0.45
DumpDocMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected