forked from equinixmetal-archive/packngo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metros.go
42 lines (33 loc) · 943 Bytes
/
metros.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
package packngo
const metroBasePath = "/locations/metros"
// MetroService interface defines available metro methods
type MetroService interface {
List(*ListOptions) ([]Metro, *Response, error)
}
type metroRoot struct {
Metros []Metro `json:"metros"`
}
// Metro represents an Equinix Metal metro
type Metro struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Code string `json:"code,omitempty"`
Country string `json:"country,omitempty"`
}
func (f Metro) String() string {
return Stringify(f)
}
// MetroServiceOp implements MetroService
type MetroServiceOp struct {
client *Client
}
// List returns all metros
func (s *MetroServiceOp) List(opts *ListOptions) ([]Metro, *Response, error) {
root := new(metroRoot)
apiPathQuery := opts.WithQuery(metroBasePath)
resp, err := s.client.DoRequest("GET", apiPathQuery, nil, root)
if err != nil {
return nil, resp, err
}
return root.Metros, resp, err
}