-
Notifications
You must be signed in to change notification settings - Fork 8
/
stats.go
55 lines (44 loc) · 1.02 KB
/
stats.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 salt
import (
"context"
"encoding/json"
"strings"
)
type TMPStats map[string]interface{}
const (
CP_APPLICATIONS = "CherryPy Applications"
CP_HTTPSERVER_PREFIX = "Cheroot HTTPServer"
)
type Stats struct {
Applications Applications `json:"CherryPy Applications"`
HTTPServer HTTPServer `json:"Cheroot HTTPServer"`
}
func (c *Client) Stats(ctx context.Context) (*Stats, error) {
data, err := c.get(ctx, "Stats")
if err != nil {
return nil, err
}
var tmp TMPStats
if err := json.Unmarshal(data, &tmp); err != nil {
return nil, err
}
var (
app Applications
server HTTPServer
)
for key, val := range tmp {
if key == CP_APPLICATIONS {
td, _ := json.Marshal(val)
if err := json.Unmarshal(td, &app); err != nil {
return nil, err
}
} else if strings.HasPrefix(key, CP_HTTPSERVER_PREFIX) {
td, _ := json.Marshal(val)
if err := json.Unmarshal(td, &server); err != nil {
return nil, err
}
}
}
ret := &Stats{HTTPServer: server, Applications: app}
return ret, nil
}