operatingsystems.go 937 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package packngo
  2. const osBasePath = "/operating-systems"
  3. // OSService interface defines available operating_systems methods
  4. type OSService interface {
  5. List() ([]OS, *Response, error)
  6. }
  7. type osRoot struct {
  8. OperatingSystems []OS `json:"operating_systems"`
  9. }
  10. // OS represents a Packet operating system
  11. type OS struct {
  12. Name string `json:"name"`
  13. Slug string `json:"slug"`
  14. Distro string `json:"distro"`
  15. Version string `json:"version"`
  16. }
  17. func (o OS) String() string {
  18. return Stringify(o)
  19. }
  20. // OSServiceOp implements OSService
  21. type OSServiceOp struct {
  22. client *Client
  23. }
  24. // List returns all available operating systems
  25. func (s *OSServiceOp) List() ([]OS, *Response, error) {
  26. req, err := s.client.NewRequest("GET", osBasePath, nil)
  27. if err != nil {
  28. return nil, nil, err
  29. }
  30. root := new(osRoot)
  31. resp, err := s.client.Do(req, root)
  32. if err != nil {
  33. return nil, resp, err
  34. }
  35. return root.OperatingSystems, resp, err
  36. }