Jon Perritt | df38cca | 2014-12-04 10:59:04 -0700 | [diff] [blame] | 1 | package apiversions |
| 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 | df38cca | 2014-12-04 10:59:04 -0700 | [diff] [blame] | 6 | ) |
| 7 | |
Jon Perritt | df38cca | 2014-12-04 10:59:04 -0700 | [diff] [blame] | 8 | // APIVersion represents an API version for Neutron. It contains the status of |
| 9 | // the API, and its unique ID. |
| 10 | type APIVersion struct { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 11 | Status string `json:"status"` |
| 12 | ID string `json:"id"` |
| 13 | Links []gophercloud.Link `json:"links"` |
Jon Perritt | df38cca | 2014-12-04 10:59:04 -0700 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | // APIVersionPage is the page returned by a pager when traversing over a |
| 17 | // collection of API versions. |
| 18 | type APIVersionPage struct { |
| 19 | pagination.SinglePageBase |
| 20 | } |
| 21 | |
| 22 | // IsEmpty checks whether an APIVersionPage struct is empty. |
| 23 | func (r APIVersionPage) IsEmpty() (bool, error) { |
| 24 | is, err := ExtractAPIVersions(r) |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 25 | return len(is) == 0, err |
Jon Perritt | df38cca | 2014-12-04 10:59:04 -0700 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | // ExtractAPIVersions takes a collection page, extracts all of the elements, |
| 29 | // and returns them a slice of APIVersion structs. It is effectively a cast. |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 30 | func ExtractAPIVersions(r pagination.Page) ([]APIVersion, error) { |
| 31 | var s struct { |
| 32 | APIVersions []APIVersion `json:"versions"` |
Jon Perritt | df38cca | 2014-12-04 10:59:04 -0700 | [diff] [blame] | 33 | } |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 34 | err := (r.(APIVersionPage)).ExtractInto(&s) |
| 35 | return s.APIVersions, err |
Jon Perritt | df38cca | 2014-12-04 10:59:04 -0700 | [diff] [blame] | 36 | } |