github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/db/v1/flavors/results.go (about) 1 package flavors 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // GetResult temporarily holds the response from a Get call. 9 type GetResult struct { 10 golangsdk.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 []golangsdk.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 flavors, err := ExtractFlavors(page) 49 return len(flavors) == 0, err 50 } 51 52 // NextPageURL uses the response's embedded link reference to navigate to the next page of results. 53 func (page FlavorPage) NextPageURL() (string, error) { 54 var s struct { 55 Links []golangsdk.Link `json:"flavors_links"` 56 } 57 err := page.ExtractInto(&s) 58 if err != nil { 59 return "", err 60 } 61 return golangsdk.ExtractNextURL(s.Links) 62 } 63 64 // ExtractFlavors provides access to the list of flavors in a page acquired from the List operation. 65 func ExtractFlavors(r pagination.Page) ([]Flavor, error) { 66 var s struct { 67 Flavors []Flavor `json:"flavors"` 68 } 69 err := (r.(FlavorPage)).ExtractInto(&s) 70 return s.Flavors, err 71 }