github.com/gophercloud/gophercloud@v1.11.0/openstack/orchestration/v1/apiversions/results.go (about) 1 package apiversions 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // APIVersion represents an API version for Neutron. It contains the status of 9 // the API, and its unique ID. 10 type APIVersion struct { 11 Status string `json:"status"` 12 ID string `json:"id"` 13 Links []gophercloud.Link `json:"links"` 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 if r.StatusCode == 204 { 25 return true, nil 26 } 27 28 is, err := ExtractAPIVersions(r) 29 return len(is) == 0, err 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. 34 func ExtractAPIVersions(r pagination.Page) ([]APIVersion, error) { 35 var s struct { 36 APIVersions []APIVersion `json:"versions"` 37 } 38 err := (r.(APIVersionPage)).ExtractInto(&s) 39 return s.APIVersions, err 40 }