github.com/gophercloud/gophercloud@v1.11.0/openstack/blockstorage/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 Cinder. 9 type APIVersion struct { 10 ID string `json:"id"` // unique identifier 11 Status string `json:"status"` // current status 12 Updated string `json:"updated"` // date last updated 13 } 14 15 // APIVersionPage is the page returned by a pager when traversing over a 16 // collection of API versions. 17 type APIVersionPage struct { 18 pagination.SinglePageBase 19 } 20 21 // IsEmpty checks whether an APIVersionPage struct is empty. 22 func (r APIVersionPage) IsEmpty() (bool, error) { 23 if r.StatusCode == 204 { 24 return true, nil 25 } 26 27 is, err := ExtractAPIVersions(r) 28 return len(is) == 0, err 29 } 30 31 // ExtractAPIVersions takes a collection page, extracts all of the elements, 32 // and returns them a slice of APIVersion structs. It is effectively a cast. 33 func ExtractAPIVersions(r pagination.Page) ([]APIVersion, error) { 34 var s struct { 35 Versions []APIVersion `json:"versions"` 36 } 37 err := (r.(APIVersionPage)).ExtractInto(&s) 38 return s.Versions, err 39 } 40 41 // GetResult represents the result of a get operation. 42 type GetResult struct { 43 gophercloud.Result 44 } 45 46 // Extract is a function that accepts a result and extracts an API version resource. 47 func (r GetResult) Extract() (*APIVersion, error) { 48 var s struct { 49 Version *APIVersion `json:"version"` 50 } 51 err := r.ExtractInto(&s) 52 return s.Version, err 53 }