github.com/gophercloud/gophercloud@v1.11.0/openstack/db/v1/flavors/results.go (about) 1 package flavors 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // GetResult temporarily holds the response from a Get call. 9 type GetResult struct { 10 gophercloud.Result 11 } 12 13 // Extract provides access to the individual Flavor returned by the Get function. 14 func (r GetResult) Extract() (*Flavor, error) { 15 var s struct { 16 Flavor *Flavor `json:"flavor"` 17 } 18 err := r.ExtractInto(&s) 19 return s.Flavor, err 20 } 21 22 // Flavor records represent (virtual) hardware configurations for server resources in a region. 23 type Flavor struct { 24 // The flavor's unique identifier. 25 // Contains 0 if the ID is not an integer. 26 ID int `json:"id"` 27 28 // The RAM capacity for the flavor. 29 RAM int `json:"ram"` 30 31 // The Name field provides a human-readable moniker for the flavor. 32 Name string `json:"name"` 33 34 // Links to access the flavor. 35 Links []gophercloud.Link 36 37 // The flavor's unique identifier as a string 38 StrID string `json:"str_id"` 39 } 40 41 // FlavorPage contains a single page of the response from a List call. 42 type FlavorPage struct { 43 pagination.LinkedPageBase 44 } 45 46 // IsEmpty determines if a page contains any results. 47 func (page FlavorPage) IsEmpty() (bool, error) { 48 if page.StatusCode == 204 { 49 return true, nil 50 } 51 52 flavors, err := ExtractFlavors(page) 53 return len(flavors) == 0, err 54 } 55 56 // NextPageURL uses the response's embedded link reference to navigate to the next page of results. 57 func (page FlavorPage) NextPageURL() (string, error) { 58 var s struct { 59 Links []gophercloud.Link `json:"flavors_links"` 60 } 61 err := page.ExtractInto(&s) 62 if err != nil { 63 return "", err 64 } 65 return gophercloud.ExtractNextURL(s.Links) 66 } 67 68 // ExtractFlavors provides access to the list of flavors in a page acquired from the List operation. 69 func ExtractFlavors(r pagination.Page) ([]Flavor, error) { 70 var s struct { 71 Flavors []Flavor `json:"flavors"` 72 } 73 err := (r.(FlavorPage)).ExtractInto(&s) 74 return s.Flavors, err 75 }