blob: 0700ab0afb8a3cd9ec760241c8ab9ce4139a7f61 [file] [log] [blame]
Jon Perrittdf38cca2014-12-04 10:59:04 -07001package apiversions
2
3import (
4 "github.com/mitchellh/mapstructure"
Jon Perritt21b3eee2015-02-11 12:23:08 -07005 "github.com/rackspace/gophercloud"
Jon Perrittdf38cca2014-12-04 10:59:04 -07006 "github.com/rackspace/gophercloud/pagination"
7)
8
Jon Perrittdf38cca2014-12-04 10:59:04 -07009// APIVersion represents an API version for Neutron. It contains the status of
10// the API, and its unique ID.
11type APIVersion struct {
Jon Perritt21b3eee2015-02-11 12:23:08 -070012 Status string `mapstructure:"status"`
13 ID string `mapstructure:"id"`
14 Links []gophercloud.Link `mapstructure:"links"`
Jon Perrittdf38cca2014-12-04 10:59:04 -070015}
16
17// APIVersionPage is the page returned by a pager when traversing over a
18// collection of API versions.
19type APIVersionPage struct {
20 pagination.SinglePageBase
21}
22
23// IsEmpty checks whether an APIVersionPage struct is empty.
24func (r APIVersionPage) IsEmpty() (bool, error) {
25 is, err := ExtractAPIVersions(r)
26 if err != nil {
27 return true, err
28 }
29 return len(is) == 0, nil
30}
31
32// ExtractAPIVersions takes a collection page, extracts all of the elements,
33// and returns them a slice of APIVersion structs. It is effectively a cast.
34func ExtractAPIVersions(page pagination.Page) ([]APIVersion, error) {
35 var resp struct {
36 Versions []APIVersion `mapstructure:"versions"`
37 }
38
39 err := mapstructure.Decode(page.(APIVersionPage).Body, &resp)
40
41 return resp.Versions, err
42}