github.com/gophercloud/gophercloud@v1.11.0/openstack/loadbalancer/v2/flavorprofiles/results.go (about) 1 package flavorprofiles 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // FlavorProfile provide metadata such as provider, toplogy and instance flavor. 9 type FlavorProfile struct { 10 // The unique ID for the Flavor 11 ID string `json:"id"` 12 13 // Human-readable name for the Flavor. Does not have to be unique. 14 Name string `json:"name"` 15 16 // Name of the provider 17 ProviderName string `json:"provider_name"` 18 19 // Flavor data 20 FlavorData string `json:"flavor_data"` 21 } 22 23 // FlavorProfilePage is the page returned by a pager when traversing over a 24 // collection of flavor profiles. 25 type FlavorProfilePage struct { 26 pagination.LinkedPageBase 27 } 28 29 // NextPageURL is invoked when a paginated collection of flavor profiles has 30 // reached the end of a page and the pager seeks to traverse over a new one. 31 // In order to do this, it needs to construct the next page's URL. 32 func (r FlavorProfilePage) NextPageURL() (string, error) { 33 var s struct { 34 Links []gophercloud.Link `json:"flavorprofiles_links"` 35 } 36 err := r.ExtractInto(&s) 37 if err != nil { 38 return "", err 39 } 40 return gophercloud.ExtractNextURL(s.Links) 41 } 42 43 // IsEmpty checks whether a FlavorProfilePage struct is empty. 44 func (r FlavorProfilePage) IsEmpty() (bool, error) { 45 is, err := ExtractFlavorProfiles(r) 46 return len(is) == 0, err 47 } 48 49 // ExtractFlavorProfiles accepts a Page struct, specifically a FlavorProfilePage 50 // struct, and extracts the elements into a slice of FlavorProfile structs. In 51 // other words, a generic collection is mapped into a relevant slice. 52 func ExtractFlavorProfiles(r pagination.Page) ([]FlavorProfile, error) { 53 var s struct { 54 FlavorProfiles []FlavorProfile `json:"flavorprofiles"` 55 } 56 err := (r.(FlavorProfilePage)).ExtractInto(&s) 57 return s.FlavorProfiles, err 58 } 59 60 type commonResult struct { 61 gophercloud.Result 62 } 63 64 // Extract is a function that accepts a result and extracts a flavor profile. 65 func (r commonResult) Extract() (*FlavorProfile, error) { 66 var s struct { 67 FlavorProfile *FlavorProfile `json:"flavorprofile"` 68 } 69 err := r.ExtractInto(&s) 70 return s.FlavorProfile, err 71 } 72 73 // CreateResult represents the result of a create operation. Call its Extract 74 // method to interpret it as a FlavorProfile. 75 type CreateResult struct { 76 commonResult 77 } 78 79 // GetResult represents the result of a get operation. Call its Extract 80 // method to interpret it as a FlavorProfile. 81 type GetResult struct { 82 commonResult 83 } 84 85 // UpdateResult represents the result of an update operation. Call its Extract 86 // method to interpret it as a FlavorProfile. 87 type UpdateResult struct { 88 commonResult 89 } 90 91 // DeleteResult represents the result of a delete operation. Call its 92 // ExtractErr method to determine if the request succeeded or failed. 93 type DeleteResult struct { 94 gophercloud.ErrResult 95 }