/
gateway_keepalive_config.go
50 lines (41 loc) · 1.08 KB
/
gateway_keepalive_config.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
package goaviatrix
import (
"context"
"fmt"
"strings"
)
func (c *Client) SetGatewayKeepaliveConfig(ctx context.Context, speed string) error {
data := map[string]string{
"action": "set_keep_alive_speed",
"CID": c.CID,
"speed": speed,
}
checkFunc := func(action, method, reason string, ret bool) error {
if ret || strings.Contains(reason, "Template is already set to") {
return nil
}
return fmt.Errorf("rest API %s %s failed: %s", action, method, reason)
}
return c.PostAPIContext(ctx, data["action"], data, checkFunc)
}
func (c *Client) GetGatewayKeepaliveConfig(ctx context.Context) (string, error) {
data := map[string]string{
"action": "get_keep_alive_speed",
"CID": c.CID,
}
type GatewayKeepaliveResults struct {
Speed string `json:"template"`
}
type GatewayKeepaliveResponse struct {
Results GatewayKeepaliveResults
}
var resp GatewayKeepaliveResponse
err := c.GetAPIContext(ctx, &resp, data["action"], data, BasicCheck)
if err != nil {
return "", err
}
if resp.Results.Speed == "" {
return "", ErrNotFound
}
return resp.Results.Speed, nil
}