Jon Perritt | 23e89c3 | 2015-01-19 15:39:45 -0700 | [diff] [blame] | 1 | package flavors |
| 2 | |
| 3 | import ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
Jon Perritt | 23e89c3 | 2015-01-19 15:39:45 -0700 | [diff] [blame] | 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. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 12 | Provider string `json:"provider"` |
Jon Perritt | 23e89c3 | 2015-01-19 15:39:45 -0700 | [diff] [blame] | 13 | // Specifies a list with an href where rel is provider_url. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 14 | Links []gophercloud.Link `json:"links"` |
Jon Perritt | 23e89c3 | 2015-01-19 15:39:45 -0700 | [diff] [blame] | 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. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 21 | ID string `json:"id"` |
Jon Perritt | 23e89c3 | 2015-01-19 15:39:45 -0700 | [diff] [blame] | 22 | // Specifies the list of providers mapped to this flavor. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 23 | Providers []Provider `json:"providers"` |
Jon Perritt | 23e89c3 | 2015-01-19 15:39:45 -0700 | [diff] [blame] | 24 | // Specifies the self-navigating JSON document paths. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 25 | Links []gophercloud.Link `json:"links"` |
Jon Perritt | 23e89c3 | 2015-01-19 15:39:45 -0700 | [diff] [blame] | 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 | flavors, err := ExtractFlavors(r) |
| 37 | if err != nil { |
| 38 | return true, err |
| 39 | } |
| 40 | return len(flavors) == 0, nil |
| 41 | } |
| 42 | |
| 43 | // ExtractFlavors extracts and returns Flavors. It is used while iterating over |
| 44 | // a flavors.List call. |
| 45 | func ExtractFlavors(page pagination.Page) ([]Flavor, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 46 | r := page.(FlavorPage) |
| 47 | var s struct { |
Jon Perritt | 23e89c3 | 2015-01-19 15:39:45 -0700 | [diff] [blame] | 48 | Flavors []Flavor `json:"flavors"` |
| 49 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 50 | err := r.ExtractInto(&s) |
| 51 | return s.Flavors, err |
Jon Perritt | 23e89c3 | 2015-01-19 15:39:45 -0700 | [diff] [blame] | 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) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 61 | var s Flavor |
| 62 | err := r.ExtractInto(&s) |
| 63 | return &s, err |
Jon Perritt | 23e89c3 | 2015-01-19 15:39:45 -0700 | [diff] [blame] | 64 | } |