2016-01-29 20:53:56 +01:00
|
|
|
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"`
|
|
|
|
}
|
2016-07-21 21:57:49 +02:00
|
|
|
|
2016-01-29 20:53:56 +01:00
|
|
|
func (o OS) String() string {
|
|
|
|
return Stringify(o)
|
|
|
|
}
|
|
|
|
|
2016-07-21 21:57:49 +02:00
|
|
|
// OSServiceOp implements OSService
|
2016-01-29 20:53:56 +01:00
|
|
|
type OSServiceOp struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
2016-07-21 21:57:49 +02:00
|
|
|
// List returns all available operating systems
|
2016-01-29 20:53:56 +01:00
|
|
|
func (s *OSServiceOp) List() ([]OS, *Response, error) {
|
|
|
|
req, err := s.client.NewRequest("GET", osBasePath, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
root := new(osRoot)
|
|
|
|
resp, err := s.client.Do(req, root)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return root.OperatingSystems, resp, err
|
|
|
|
}
|