github.com/gophercloud/gophercloud@v1.11.0/openstack/loadbalancer/v2/apiversions/results.go (about) 1 package apiversions 2 3 import "github.com/gophercloud/gophercloud/pagination" 4 5 // APIVersion represents an API version for load balancer. It contains 6 // the status of the API, and its unique ID. 7 type APIVersion struct { 8 Status string `son:"status"` 9 ID string `json:"id"` 10 } 11 12 // APIVersionPage is the page returned by a pager when traversing over a 13 // collection of API versions. 14 type APIVersionPage struct { 15 pagination.SinglePageBase 16 } 17 18 // IsEmpty checks whether an APIVersionPage struct is empty. 19 func (r APIVersionPage) IsEmpty() (bool, error) { 20 if r.StatusCode == 204 { 21 return true, nil 22 } 23 24 is, err := ExtractAPIVersions(r) 25 return len(is) == 0, err 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. 30 func ExtractAPIVersions(r pagination.Page) ([]APIVersion, error) { 31 var s struct { 32 Versions []APIVersion `json:"versions"` 33 } 34 err := (r.(APIVersionPage)).ExtractInto(&s) 35 return s.Versions, err 36 }