-
Notifications
You must be signed in to change notification settings - Fork 510
/
results.go
98 lines (82 loc) · 2.62 KB
/
results.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package flavors
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// Flavor provide specs for the creation of a load balancer.
type Flavor struct {
// The unique ID for the Flavor
ID string `json:"id"`
// Human-readable name for the Flavor. Does not have to be unique.
Name string `json:"name"`
// Human-readable description for the Flavor.
Description string `json:"description"`
// Status of the Flavor.
Enabled bool `json:"enabled"`
// Flavor Profile apply to this Flavor.
FlavorProfileId string `json:"flavor_profile_id"`
}
// FlavorPage is the page returned by a pager when traversing over a
// collection of flavors.
type FlavorPage struct {
pagination.LinkedPageBase
}
// NextPageURL is invoked when a paginated collection of flavors has
// reached the end of a page and the pager seeks to traverse over a new one.
// In order to do this, it needs to construct the next page's URL.
func (r FlavorPage) NextPageURL() (string, error) {
var s struct {
Links []gophercloud.Link `json:"flavors_links"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return gophercloud.ExtractNextURL(s.Links)
}
// IsEmpty checks whether a FlavorPage struct is empty.
func (r FlavorPage) IsEmpty() (bool, error) {
is, err := ExtractFlavors(r)
return len(is) == 0, err
}
// ExtractFlavors accepts a Page struct, specifically a FlavorPage
// struct, and extracts the elements into a slice of Flavor structs. In
// other words, a generic collection is mapped into a relevant slice.
func ExtractFlavors(r pagination.Page) ([]Flavor, error) {
var s struct {
Flavors []Flavor `json:"flavors"`
}
err := (r.(FlavorPage)).ExtractInto(&s)
return s.Flavors, err
}
type commonResult struct {
gophercloud.Result
}
// Extract is a function that accepts a result and extracts a flavor.
func (r commonResult) Extract() (*Flavor, error) {
var s struct {
Flavor *Flavor `json:"flavor"`
}
err := r.ExtractInto(&s)
return s.Flavor, err
}
// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a Flavor.
type CreateResult struct {
commonResult
}
// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Flavor.
type GetResult struct {
commonResult
}
// UpdateResult represents the result of an update operation. Call its Extract
// method to interpret it as a Flavor.
type UpdateResult struct {
commonResult
}
// DeleteResult represents the result of a delete operation. Call its
// ExtractErr method to determine if the request succeeded or failed.
type DeleteResult struct {
gophercloud.ErrResult
}