-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
60 lines (47 loc) · 1.56 KB
/
debug.go
File metadata and controls
60 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package peerdb
import (
"net/http"
"gitlab.com/tozd/go/errors"
"gitlab.com/tozd/go/x"
"gitlab.com/tozd/waf"
"gitlab.com/peerdb/peerdb/document"
internalSearch "gitlab.com/peerdb/peerdb/internal/search"
)
// DebugMappingGetAPI handles GET requests to serve generated ElasticSearch mapping for debugging.
func (s *Service) DebugMappingGetAPI(w http.ResponseWriter, req *http.Request, _ waf.Params) {
if !s.Development {
s.NotFoundWithError(w, req, errors.New("not in development mode"))
return
}
indexConfiguration, errE := internalSearch.Mapping()
if errE != nil {
s.InternalServerErrorWithError(w, req, errE)
return
}
s.WriteJSON(w, req, indexConfiguration, nil)
}
// DebugIndexedGetAPI handles GET requests to return a document as it would be converted and indexed to ElasticSearch.
func (s *Service) DebugIndexedGetAPI(w http.ResponseWriter, req *http.Request, params waf.Params) {
if !s.Development {
s.NotFoundWithError(w, req, errors.New("not in development mode"))
return
}
dataJSON, metadata, version, handled := s.documentGetData(w, req, params)
if handled {
return
}
var doc document.D
errE := x.UnmarshalWithoutUnknownFields(dataJSON, &doc)
if errE != nil {
s.InternalServerErrorWithError(w, req, errE)
return
}
site := waf.MustGetSite[*Site](req.Context())
searchDoc, errE := site.Base.Bridge().Converter().FromDocument(req.Context(), &doc, metadata.InverseRelations)
if errE != nil {
s.InternalServerErrorWithError(w, req, errE)
return
}
w.Header().Set("Version", version.String())
s.WriteJSON(w, req, searchDoc, nil)
}