This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
facilities.go
67 lines (55 loc) · 1.8 KB
/
facilities.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 packngo
const facilityBasePath = "/facilities"
// FacilityService interface defines available facility methods
type FacilityService interface {
List(*ListOptions) ([]Facility, *Response, error)
}
type facilityRoot struct {
Facilities []Facility `json:"facilities"`
}
// Facility represents an Equinix Metal facility
type Facility struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Code string `json:"code,omitempty"`
Features []string `json:"features,omitempty"`
Address *Address `json:"address,omitempty"`
Metro *Metro `json:"metro,omitempty"`
URL string `json:"href,omitempty"`
}
func (f Facility) String() string {
return Stringify(f)
}
// Coordinates struct for Coordinates
type Coordinates struct {
Latitude *string `json:"latitude,omitempty"`
Longitude *string `json:"longitude,omitempty"`
}
// Address - the physical address of the facility
type Address struct {
ID string `json:"id,omitempty"`
Address string `json:"address"`
Address2 *string `json:"address2,omitempty"`
City *string `json:"city,omitempty"`
State *string `json:"state,omitempty"`
ZipCode string `json:"zip_code"`
Country string `json:"country"`
Coordinates *Coordinates `json:"coordinates,omitempty"`
}
func (a Address) String() string {
return Stringify(a)
}
// FacilityServiceOp implements FacilityService
type FacilityServiceOp struct {
client *Client
}
// List returns all facilities
func (s *FacilityServiceOp) List(opts *ListOptions) ([]Facility, *Response, error) {
root := new(facilityRoot)
apiPathQuery := opts.WithQuery(facilityBasePath)
resp, err := s.client.DoRequest("GET", apiPathQuery, nil, root)
if err != nil {
return nil, resp, err
}
return root.Facilities, resp, err
}