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