1package flavors 2 3import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6) 7 8// Provider represents a provider for a particular flavor. 9type Provider struct { 10 // Specifies the name of the provider. The name must not exceed 64 bytes in 11 // length and is limited to unicode, digits, underscores, and hyphens. 12 Provider string `json:"provider"` 13 // Specifies a list with an href where rel is provider_url. 14 Links []gophercloud.Link `json:"links"` 15} 16 17// Flavor represents a mapping configuration to a CDN provider. 18type Flavor struct { 19 // Specifies the name of the flavor. The name must not exceed 64 bytes in 20 // length and is limited to unicode, digits, underscores, and hyphens. 21 ID string `json:"id"` 22 // Specifies the list of providers mapped to this flavor. 23 Providers []Provider `json:"providers"` 24 // Specifies the self-navigating JSON document paths. 25 Links []gophercloud.Link `json:"links"` 26} 27 28// FlavorPage is the page returned by a pager when traversing over a 29// collection of CDN flavors. 30type FlavorPage struct { 31 pagination.SinglePageBase 32} 33 34// IsEmpty returns true if a FlavorPage contains no Flavors. 35func (r FlavorPage) IsEmpty() (bool, error) { 36 flavors, err := ExtractFlavors(r) 37 return len(flavors) == 0, err 38} 39 40// ExtractFlavors extracts and returns Flavors. It is used while iterating over 41// a flavors.List call. 42func ExtractFlavors(r pagination.Page) ([]Flavor, error) { 43 var s struct { 44 Flavors []Flavor `json:"flavors"` 45 } 46 err := (r.(FlavorPage)).ExtractInto(&s) 47 return s.Flavors, err 48} 49 50// GetResult represents the result of a get operation. 51type GetResult struct { 52 gophercloud.Result 53} 54 55// Extract is a function that extracts a flavor from a GetResult. 56func (r GetResult) Extract() (*Flavor, error) { 57 var s *Flavor 58 err := r.ExtractInto(&s) 59 return s, err 60} 61