facilities.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package packngo
  2. const facilityBasePath = "/facilities"
  3. // FacilityService interface defines available facility methods
  4. type FacilityService interface {
  5. List() ([]Facility, *Response, error)
  6. }
  7. type facilityRoot struct {
  8. Facilities []Facility `json:"facilities"`
  9. }
  10. // Facility represents a Packet facility
  11. type Facility struct {
  12. ID string `json:"id"`
  13. Name string `json:"name,omitempty"`
  14. Code string `json:"code,omitempty"`
  15. Features []string `json:"features,omitempty"`
  16. Address *Address `json:"address,omitempty"`
  17. URL string `json:"href,omitempty"`
  18. }
  19. func (f Facility) String() string {
  20. return Stringify(f)
  21. }
  22. // Address - the physical address of the facility
  23. type Address struct {
  24. ID string `json:"id,omitempty"`
  25. }
  26. func (a Address) String() string {
  27. return Stringify(a)
  28. }
  29. // FacilityServiceOp implements FacilityService
  30. type FacilityServiceOp struct {
  31. client *Client
  32. }
  33. // List returns all available Packet facilities
  34. func (s *FacilityServiceOp) List() ([]Facility, *Response, error) {
  35. req, err := s.client.NewRequest("GET", facilityBasePath, nil)
  36. if err != nil {
  37. return nil, nil, err
  38. }
  39. root := new(facilityRoot)
  40. resp, err := s.client.Do(req, root)
  41. if err != nil {
  42. return nil, resp, err
  43. }
  44. return root.Facilities, resp, err
  45. }