/
monitoring.go
49 lines (42 loc) · 1.14 KB
/
monitoring.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
package api
import (
"math"
"strconv"
)
func (api *WebAPI) GetSnapshotsWithinRange(r *Request) {
id, err := strconv.ParseInt(r.Ctx.UserValue("id").(string), 10, 64)
from := r.Ctx.Request.URI().QueryArgs().GetUintOrZero("from")
to := r.Ctx.Request.URI().QueryArgs().GetUintOrZero("to")
if err != nil || id <= 0 || from <= 0 || to <= 0 || from >= math.MaxInt32 || to >= math.MaxInt32 {
r.Json(JsonResponse{
Ok: false,
Message: "Invalid request",
}, 400)
return
}
snapshots := api.Database.GetMonitoringSnapshotsBetween(id, from, to)
r.OkJson(JsonResponse{
Ok: true,
Content: GetSnapshotsResponse{
Snapshots: snapshots,
},
})
}
func (api *WebAPI) GetNSnapshots(r *Request) {
id, err := strconv.ParseInt(r.Ctx.UserValue("id").(string), 10, 64)
count := r.Ctx.Request.URI().QueryArgs().GetUintOrZero("count")
if err != nil || id <= 0 || count <= 0 || count >= 1000 {
r.Json(JsonResponse{
Ok: false,
Message: "Invalid request",
}, 400)
return
}
snapshots := api.Database.GetNMonitoringSnapshots(id, count)
r.OkJson(JsonResponse{
Ok: true,
Content: GetSnapshotsResponse{
Snapshots: snapshots,
},
})
}