forked from mercari/gaurun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat.go
55 lines (47 loc) · 1.44 KB
/
stat.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
package gaurun
import (
"encoding/json"
"fmt"
"net/http"
"sync/atomic"
)
type StatApp struct {
QueueMax int `json:"queue_max"`
QueueUsage int `json:"queue_usage"`
Ios StatIos `json:"ios"`
Android StatAndroid `json:"android"`
}
type StatAndroid struct {
PushSuccess int64 `json:"push_success"`
PushError int64 `json:"push_error"`
}
type StatIos struct {
PushSuccess int64 `json:"push_success"`
PushError int64 `json:"push_error"`
}
func InitStatGaurun() {
StatGaurun.QueueUsage = 0
StatGaurun.Ios.PushSuccess = 0
StatGaurun.Ios.PushError = 0
StatGaurun.Android.PushSuccess = 0
StatGaurun.Android.PushError = 0
}
func StatsGaurunHandler(w http.ResponseWriter, r *http.Request) {
var result StatApp
result.QueueMax = cap(QueueNotification)
result.QueueUsage = len(QueueNotification)
result.Ios.PushSuccess = atomic.LoadInt64(&StatGaurun.Ios.PushSuccess)
result.Ios.PushError = atomic.LoadInt64(&StatGaurun.Ios.PushError)
result.Android.PushSuccess = atomic.LoadInt64(&StatGaurun.Android.PushSuccess)
result.Android.PushError = atomic.LoadInt64(&StatGaurun.Android.PushError)
respBody, err := json.MarshalIndent(result, "", " ")
if err != nil {
msg := "Response-body could not be created"
LogError.Error(msg)
http.Error(w, msg, http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Server", serverHeader())
fmt.Fprintf(w, string(respBody))
}