github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v3/domains/results.go (about) 1 package domains 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/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 golangsdk.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 golangsdk.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 domains, err := ExtractDomains(r) 62 return len(domains) == 0, err 63 } 64 65 // NextPageURL extracts the "next" link from the links section of the result. 66 func (r DomainPage) NextPageURL() (string, error) { 67 var s struct { 68 Links struct { 69 Next string `json:"next"` 70 Previous string `json:"previous"` 71 } `json:"links"` 72 } 73 err := r.ExtractInto(&s) 74 if err != nil { 75 return "", err 76 } 77 return s.Links.Next, err 78 } 79 80 // ExtractDomains returns a slice of Domains contained in a single page of 81 // results. 82 func ExtractDomains(r pagination.Page) ([]Domain, error) { 83 var s struct { 84 Domains []Domain `json:"domains"` 85 } 86 err := (r.(DomainPage)).ExtractInto(&s) 87 return s.Domains, err 88 } 89 90 // Extract interprets any domainResults as a Domain. 91 func (r domainResult) Extract() (*Domain, error) { 92 var s struct { 93 Domain *Domain `json:"domain"` 94 } 95 err := r.ExtractInto(&s) 96 return s.Domain, err 97 }