results.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package domains
  2. import (
  3. "devel.mephi.ru/iacherepanov/openstack-gophercloud"
  4. "devel.mephi.ru/iacherepanov/openstack-gophercloud/pagination"
  5. )
  6. // A Domain is a collection of projects, users, and roles.
  7. type Domain struct {
  8. // Description is the description of the Domain.
  9. Description string `json:"description"`
  10. // Enabled is whether or not the domain is enabled.
  11. Enabled bool `json:"enabled"`
  12. // ID is the unique ID of the domain.
  13. ID string `json:"id"`
  14. // Links contains referencing links to the domain.
  15. Links map[string]interface{} `json:"links"`
  16. // Name is the name of the domain.
  17. Name string `json:"name"`
  18. }
  19. type domainResult struct {
  20. gophercloud.Result
  21. }
  22. // GetResult is the response from a Get operation. Call its Extract method
  23. // to interpret it as a Domain.
  24. type GetResult struct {
  25. domainResult
  26. }
  27. // CreateResult is the response from a Create operation. Call its Extract method
  28. // to interpret it as a Domain.
  29. type CreateResult struct {
  30. domainResult
  31. }
  32. // DeleteResult is the response from a Delete operation. Call its ExtractErr to
  33. // determine if the request succeeded or failed.
  34. type DeleteResult struct {
  35. gophercloud.ErrResult
  36. }
  37. // UpdateResult is the result of an Update request. Call its Extract method to
  38. // interpret it as a Domain.
  39. type UpdateResult struct {
  40. domainResult
  41. }
  42. // DomainPage is a single page of Domain results.
  43. type DomainPage struct {
  44. pagination.LinkedPageBase
  45. }
  46. // IsEmpty determines whether or not a page of Domains contains any results.
  47. func (r DomainPage) IsEmpty() (bool, error) {
  48. domains, err := ExtractDomains(r)
  49. return len(domains) == 0, err
  50. }
  51. // NextPageURL extracts the "next" link from the links section of the result.
  52. func (r DomainPage) NextPageURL() (string, error) {
  53. var s struct {
  54. Links struct {
  55. Next string `json:"next"`
  56. Previous string `json:"previous"`
  57. } `json:"links"`
  58. }
  59. err := r.ExtractInto(&s)
  60. if err != nil {
  61. return "", err
  62. }
  63. return s.Links.Next, err
  64. }
  65. // ExtractDomains returns a slice of Domains contained in a single page of
  66. // results.
  67. func ExtractDomains(r pagination.Page) ([]Domain, error) {
  68. var s struct {
  69. Domains []Domain `json:"domains"`
  70. }
  71. err := (r.(DomainPage)).ExtractInto(&s)
  72. return s.Domains, err
  73. }
  74. // Extract interprets any domainResults as a Domain.
  75. func (r domainResult) Extract() (*Domain, error) {
  76. var s struct {
  77. Domain *Domain `json:"domain"`
  78. }
  79. err := r.ExtractInto(&s)
  80. return s.Domain, err
  81. }