-
Notifications
You must be signed in to change notification settings - Fork 1
/
http_debug.go
57 lines (45 loc) · 948 Bytes
/
http_debug.go
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
package main
import (
"fmt"
"net/http"
"runtime"
"github.com/AudioAddict/go-echoprint/echoprint"
)
var statsInfo *stats
func init() {
statsInfo = &stats{
Memory: new(runtime.MemStats),
}
}
type stats struct {
Memory *runtime.MemStats
}
func debugHandler(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
op := r.FormValue("debug_op")
data := r.FormValue("data")
var err error
var results interface{}
switch op {
case "Ingest":
results, err = peformIngest([]byte(data))
case "Query":
results, err = peformQuery([]byte(data))
}
if err != nil {
apiError(w, err)
return
}
renderResponse(w, results)
} else {
renderView(w, "debug", nil)
}
}
func statsHandler(w http.ResponseWriter, r *http.Request) {
runtime.ReadMemStats(statsInfo.Memory)
renderResponse(w, statsInfo)
}
func purgeHandler(w http.ResponseWriter, r *http.Request) {
echoprint.Purge()
fmt.Fprint(w, "Done")
}