forked from nl2go/hrobot-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfailover.go
45 lines (36 loc) · 878 Bytes
/
failover.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
package client
import (
"encoding/json"
"fmt"
"github.com/syself/hrobot-go/models"
)
func (c *Client) FailoverGetList() ([]models.Failover, error) {
url := c.baseURL + "/failover"
bytes, err := c.doGetRequest(url)
if err != nil {
return nil, err
}
var failoverList []models.FailoverResponse
err = json.Unmarshal(bytes, &failoverList)
if err != nil {
return nil, err
}
var data []models.Failover
for _, failover := range failoverList {
data = append(data, failover.Failover)
}
return data, nil
}
func (c *Client) FailoverGet(ip string) (*models.Failover, error) {
url := fmt.Sprintf(c.baseURL+"/failover/%s", ip)
bytes, err := c.doGetRequest(url)
if err != nil {
return nil, err
}
var failoverResp models.FailoverResponse
err = json.Unmarshal(bytes, &failoverResp)
if err != nil {
return nil, err
}
return &failoverResp.Failover, nil
}