-
Notifications
You must be signed in to change notification settings - Fork 1
/
info.go
92 lines (78 loc) · 2.34 KB
/
info.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package http
import (
"fmt"
"net/http"
"strings"
"github.com/fwtpe/owl-backend/common/utils"
"github.com/fwtpe/owl-backend/modules/judge/g"
"github.com/fwtpe/owl-backend/modules/judge/store"
)
func configInfoRoutes() {
// e.g. /strategy/lg-dinp-docker01.bj/cpu.idle
http.HandleFunc("/strategy/", func(w http.ResponseWriter, r *http.Request) {
urlParam := r.URL.Path[len("/strategy/"):]
m := g.StrategyMap.Get()
RenderDataJson(w, m[urlParam])
})
// e.g. /expression/net.port.listen/port=22
http.HandleFunc("/expression/", func(w http.ResponseWriter, r *http.Request) {
urlParam := r.URL.Path[len("/expression/"):]
m := g.ExpressionMap.Get()
RenderDataJson(w, m[urlParam])
})
http.HandleFunc("/count", func(w http.ResponseWriter, r *http.Request) {
sum := 0
arr := []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}
for i := 0; i < 16; i++ {
for j := 0; j < 16; j++ {
sum += store.HistoryBigMap[arr[i]+arr[j]].Len()
}
}
out := fmt.Sprintf("total: %d\n", sum)
w.Write([]byte(out))
})
http.HandleFunc("/history/", func(w http.ResponseWriter, r *http.Request) {
urlParam := r.URL.Path[len("/history/"):]
pk := utils.Md5(urlParam)
L, exists := store.HistoryBigMap[pk[0:2]].Get(pk)
if !exists || L.Len() == 0 {
w.Write([]byte("not found\n"))
return
}
arr := []string{}
datas, _ := L.HistoryData(g.Config().Remain - 1)
for i := 0; i < len(datas); i++ {
if datas[i] == nil {
continue
}
str := fmt.Sprintf(
"%d %s %v\n",
datas[i].Timestamp,
utils.UnixTsFormat(datas[i].Timestamp),
datas[i].Value,
)
arr = append(arr, str)
}
w.Write([]byte(strings.Join(arr, "")))
})
http.HandleFunc("/api/judges/list", func(w http.ResponseWriter, r *http.Request) {
judgeRes := g.LastEvents.GetAll()
RenderDataJson(w, judgeRes)
})
http.HandleFunc("/api/judges/delete", func(w http.ResponseWriter, r *http.Request) {
key := r.URL.Query().Get("key")
reposCode := "failed"
var msg string
if key != "" {
exist := g.LastEvents.Delete(key)
if exist == false {
reposCode = "success"
} else {
msg = fmt.Sprintf("trying to delete judge, but it failed! inputed key: %s", key)
}
} else {
msg = fmt.Sprintf("judge is failed, hash key is empyt!")
}
RenderDataJson(w, map[string]string{"status": reposCode, "msg": msg})
})
}