-
Notifications
You must be signed in to change notification settings - Fork 15
/
results.go
61 lines (51 loc) · 1.44 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 triggers
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
type TriggerResp struct {
TriggerInfo TriggerResponse `json:"trigger_info"`
}
type TriggerResponse struct {
ID string `json:"id" required:"true"`
PlanID string `json:"plan_id" required:"true"`
Name string `json:"name" required:"true"`
Properties *PropertiesOpts `json:"properties" required:"true"`
}
type PropertiesOpts struct {
Pattern string `json:"pattern" required:"true"`
MaxBackups int `json:"max_backups,omitempty"`
}
type commonResult struct {
gophercloud.Result
}
func (r commonResult) Extract() (*TriggerResponse, error) {
var s *TriggerResp
if err := r.ExtractInto(&s); err != nil {
return nil, err
}
return &s.TriggerInfo, nil
}
type CreateResult struct {
commonResult
}
// Page represents a page of backup triggers
type Page struct {
pagination.SinglePageBase
}
// IsEmpty indicates whether a backup trigger collection is empty.
func (r Page) IsEmpty() (bool, error) {
tr, err := ExtractTriggers(r)
return len(tr) == 0, err
}
// ExtractTriggers retrieves a slice of backup TriggerResponse structs from a paginated
// collection.
func ExtractTriggers(r pagination.Page) ([]TriggerResponse, error) {
var s struct {
Triggers []TriggerResponse `json:"triggers"`
}
if err := (r.(Page)).ExtractInto(&s); err != nil {
return nil, err
}
return s.Triggers, nil
}