This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
results.go
69 lines (59 loc) · 1.7 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
package groups
import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)
// GroupCreate response
type GroupCreate struct {
ID string `json:"id"`
Name string `json:"name"`
}
// CreateResult is a struct that contains all the return parameters of creation
type CreateResult struct {
golangsdk.Result
}
// Extract from CreateResult
func (r CreateResult) Extract() ([]GroupCreate, error) {
var s struct {
GroupsCreate []GroupCreate `json:"groups"`
}
err := r.Result.ExtractInto(&s)
return s.GroupsCreate, err
}
// DeleteResult is a struct which contains the result of deletion
type DeleteResult struct {
golangsdk.ErrResult
}
// Group response
type Group struct {
ID string `json:"id"`
Name string `json:"name"`
ConsumedMessages int `json:"consumed_messages"`
AvailableMessages int `json:"available_messages"`
ProducedMessages int `json:"produced_messages"`
ProducedDeadletters int `json:"produced_deadletters"`
AvailableDeadletters int `json:"available_deadletters"`
}
type Groups struct {
QueueId string `json:"queue_id"`
QueueName string `json:"queue_name"`
Details []Group `json:"groups"`
}
// GroupPage may be embedded in a Page
// that contains all of the results from an operation at once.
type GroupPage struct {
pagination.SinglePageBase
}
// IsEmpty returns true if a ListResult contains no groups.
func (r GroupPage) IsEmpty() (bool, error) {
rs, err := ExtractGroups(r)
return len(rs) == 0, err
}
// ExtractGroups from List
func ExtractGroups(r pagination.Page) ([]Group, error) {
var s struct {
Groups []Group `json:"groups"`
}
err := (r.(GroupPage)).ExtractInto(&s)
return s.Groups, err
}