-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.go
80 lines (72 loc) · 1.69 KB
/
server.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
package acapy
func (c *Client) Plugins() ([]string, error) {
var result = struct {
Result []string `json:"result"`
}{}
err := c.get("/plugins", nil, &result)
if err != nil {
return nil, err
}
return result.Result, nil
}
type Status struct {
Version string `json:"version"`
Label string `json:"label"`
Conductor struct {
InSessions int `json:"in_sessions"`
OutEncode int `json:"out_encode"`
OutDeliver int `json:"out_deliver"`
TaskActive int `json:"task_active"`
TaskDone int `json:"task_done"`
TaskFailed int `json:"task_failed"`
TaskPending int `json:"task_pending"`
} `json:"conductor"`
}
func (c *Client) Status() (Status, error) {
var status Status
err := c.get("/status", nil, &status)
if err != nil {
return Status{}, err
}
return status, nil
}
func (c *Client) ResetStatistics() error {
return c.post("/status/reset", nil, nil, nil)
}
func (c *Client) IsAlive() (bool, error) {
var result = struct {
Alive bool `json:"alive"`
}{}
err := c.get("/status/live", nil, &result)
if err != nil {
return false, err
}
return result.Alive, nil
}
func (c *Client) IsReady() (bool, error) {
var result = struct {
Ready bool `json:"ready"`
}{}
err := c.get("/status/ready", nil, &result)
if err != nil {
return false, err
}
return result.Ready, nil
}
func (c *Client) Shutdown() error {
return c.get("/shutdown", nil, nil)
}
func (c *Client) Features() ([]string, error) {
var result = struct {
Results map[string]interface{} `json:"results"`
}{}
err := c.get("/features", nil, &result)
if err != nil {
return nil, err
}
var features []string
for feature, _ := range result.Results {
features = append(features, feature)
}
return features, nil
}