forked from appscode/go-hetzner
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfailover.go
More file actions
69 lines (55 loc) · 2.29 KB
/
failover.go
File metadata and controls
69 lines (55 loc) · 2.29 KB
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
package hetzner
import (
"fmt"
"net/http"
)
// API: https://robot.your-server.de/doc/webservice/en.html#failover
// FailoverService represents a service to work with failover ips.
type FailoverService interface {
// List Query failover data for all servers
// See: https://robot.your-server.de/doc/webservice/en.html#get-failover
List() ([]*Failover, *http.Response, error)
// Get Query specific failover IP address data
// See: https://robot.your-server.de/doc/webservice/en.html#get-failover-failover-ip
Get(failoverIP string) (*Failover, *http.Response, error)
// Switch traffic of failoverIP to the server with ip newActiveIP.
// When successful, returns updated information about the failover IP
// See: https://robot.your-server.de/doc/webservice/en.html#post-failover-failover-ip
Switch(req FailoverSwitchRequest) (*Failover, *http.Response, error)
// Delete the routing of a failover IP
// When successful, returns updated information about the failover IP
// See: https://robot.your-server.de/doc/webservice/en.html#delete-failover-failover-ip
Delete(failoverIP string) (*Failover, *http.Response, error)
}
type FailoverServiceImpl struct {
client *Client
}
var _ FailoverService = &FailoverServiceImpl{}
func (s *FailoverServiceImpl) List() ([]*Failover, *http.Response, error) {
path := "/failover"
data := make([]dataFailover, 0)
resp, err := s.client.Call(http.MethodGet, path, nil, &data)
a := make([]*Failover, len(data))
for i, d := range data {
a[i] = d.Failover
}
return a, resp, err
}
func (s *FailoverServiceImpl) Get(failoverIP string) (*Failover, *http.Response, error) {
path := fmt.Sprintf("/failover/%s", failoverIP)
data := dataFailover{}
resp, err := s.client.Call(http.MethodGet, path, nil, &data)
return data.Failover, resp, err
}
func (s *FailoverServiceImpl) Switch(req FailoverSwitchRequest) (*Failover, *http.Response, error) {
path := fmt.Sprintf("/failover/%s", req.FailoverIP)
data := dataFailover{}
resp, err := s.client.Call(http.MethodPost, path, req, &data)
return data.Failover, resp, err
}
func (s *FailoverServiceImpl) Delete(failoverIP string) (*Failover, *http.Response, error) {
path := fmt.Sprintf("/failover/%s", failoverIP)
data := dataFailover{}
resp, err := s.client.Call(http.MethodDelete, path, nil, &data)
return data.Failover, resp, err
}