forked from equinixmetal-archive/packngo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperatingsystems.go
41 lines (32 loc) · 862 Bytes
/
operatingsystems.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
package packngo
const osBasePath = "/operating-systems"
// OSService interface defines available operating_systems methods
type OSService interface {
List() ([]OS, *Response, error)
}
type osRoot struct {
OperatingSystems []OS `json:"operating_systems"`
}
// OS represents a Packet operating system
type OS struct {
Name string `json:"name"`
Slug string `json:"slug"`
Distro string `json:"distro"`
Version string `json:"version"`
}
func (o OS) String() string {
return Stringify(o)
}
// OSServiceOp implements OSService
type OSServiceOp struct {
client *Client
}
// List returns all available operating systems
func (s *OSServiceOp) List() ([]OS, *Response, error) {
root := new(osRoot)
resp, err := s.client.DoRequest("GET", osBasePath, nil, root)
if err != nil {
return nil, resp, err
}
return root.OperatingSystems, resp, err
}