This repository has been archived by the owner on May 8, 2024. It is now read-only.
forked from huaweicloud/huaweicloud-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.go
61 lines (51 loc) · 1.69 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
package volumetypes
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// VolumeType contains all information associated with an OpenStack Volume Type.
type VolumeType struct {
ExtraSpecs map[string]interface{} `json:"extra_specs"` // user-defined metadata
ID string `json:"id"` // unique identifier
Name string `json:"name"` // display name
}
// CreateResult contains the response body and error from a Create request.
type CreateResult struct {
commonResult
}
// GetResult contains the response body and error from a Get request.
type GetResult struct {
commonResult
}
// DeleteResult contains the response error from a Delete request.
type DeleteResult struct {
gophercloud.ErrResult
}
// VolumeTypePage is a pagination.Pager that is returned from a call to the List function.
type VolumeTypePage struct {
pagination.SinglePageBase
}
// IsEmpty returns true if a VolumeTypePage contains no Volume Types.
func (r VolumeTypePage) IsEmpty() (bool, error) {
volumeTypes, err := ExtractVolumeTypes(r)
return len(volumeTypes) == 0, err
}
// ExtractVolumeTypes extracts and returns Volume Types.
func ExtractVolumeTypes(r pagination.Page) ([]VolumeType, error) {
var s struct {
VolumeTypes []VolumeType `json:"volume_types"`
}
err := (r.(VolumeTypePage)).ExtractInto(&s)
return s.VolumeTypes, err
}
type commonResult struct {
gophercloud.Result
}
// Extract will get the Volume Type object out of the commonResult object.
func (r commonResult) Extract() (*VolumeType, error) {
var s struct {
VolumeType *VolumeType `json:"volume_type"`
}
err := r.ExtractInto(&s)
return s.VolumeType, err
}