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