forked from AntoineAugusti/updown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodes.go
67 lines (54 loc) · 1.54 KB
/
nodes.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
package updown
import (
"net/http"
)
// NodeService interacts with the nodes section of the API
type NodeService struct {
client *Client
}
// NodeDetails gives information about a node
type NodeDetails struct {
IP string `json:"ip,omitempty"`
IP6 string `json:"ip6,omitempty"`
City string `json:"city,omitempty"`
Country string `json:"country,omitempty"`
CountryCode string `json:"country_code,omitempty"`
}
// IPs represents IP addresses in v4 or v6
type IPs []string
// Nodes represents multiple nodes
type Nodes map[string]NodeDetails
// List gets the nodes performing checks
func (s *NodeService) List() (Nodes, *http.Response, error) {
req, err := s.client.NewRequest("GET", "nodes", nil)
if err != nil {
return nil, nil, err
}
var res Nodes
resp, err := s.client.Do(req, &res)
if err != nil {
return nil, resp, err
}
return res, resp, err
}
// ListIPv4 gets the list of IPv4 performing checks
func (s *NodeService) ListIPv4() (IPs, *http.Response, error) {
return s.genericIPList("4")
}
// ListIPv6 gets the list of IPv6 performing checks
func (s *NodeService) ListIPv6() (IPs, *http.Response, error) {
return s.genericIPList("6")
}
// genericIPList get the list of IPv4 or IPv6 IPs performing checks
func (s *NodeService) genericIPList(version string) (IPs, *http.Response, error) {
req, err := s.client.NewRequest("GET", "nodes/ipv"+version, nil)
if err != nil {
return nil, nil, err
}
var res IPs
resp, err := s.client.Do(req, &res)
if err != nil {
return nil, resp, err
}
return res, resp, err
}