github.com/gophercloud/gophercloud@v1.11.0/openstack/cdn/v1/flavors/results.go (about) 1 package flavors 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // Provider represents a provider for a particular flavor. 9 type 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. 18 type 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. 30 type FlavorPage struct { 31 pagination.SinglePageBase 32 } 33 34 // IsEmpty returns true if a FlavorPage contains no Flavors. 35 func (r FlavorPage) IsEmpty() (bool, error) { 36 if r.StatusCode == 204 { 37 return true, nil 38 } 39 40 flavors, err := ExtractFlavors(r) 41 return len(flavors) == 0, err 42 } 43 44 // ExtractFlavors extracts and returns Flavors. It is used while iterating over 45 // a flavors.List call. 46 func ExtractFlavors(r pagination.Page) ([]Flavor, error) { 47 var s struct { 48 Flavors []Flavor `json:"flavors"` 49 } 50 err := (r.(FlavorPage)).ExtractInto(&s) 51 return s.Flavors, err 52 } 53 54 // GetResult represents the result of a get operation. 55 type GetResult struct { 56 gophercloud.Result 57 } 58 59 // Extract is a function that extracts a flavor from a GetResult. 60 func (r GetResult) Extract() (*Flavor, error) { 61 var s *Flavor 62 err := r.ExtractInto(&s) 63 return s, err 64 }