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
85 lines (73 loc) · 1.87 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
package policies
import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)
type Role struct {
ID string `json:"id"`
Name string `json:"display_name"`
Catalog string `json:"catalog"`
Description string `json:"description"`
Type string `json:"type"`
Policy Policy `json:"policy" required:"true"`
DomainId string `json:"domain_id"`
References int `json:"references"`
}
type roleResult struct {
golangsdk.Result
}
// GetResult is the response from a Get operation. Call its Extract method
// to interpret it as a Role.
type GetResult struct {
roleResult
}
// CreateResult is the response from a Create operation. Call its Extract method
// to interpret it as a Role
type CreateResult struct {
roleResult
}
// UpdateResult is the response from an Update operation. Call its Extract
// method to interpret it as a Role.
type UpdateResult struct {
roleResult
}
// DeleteResult is the response from a Delete operation. Call its ExtractErr to
// determine if the request succeeded or failed.
type DeleteResult struct {
golangsdk.ErrResult
}
type RolePage struct {
pagination.LinkedPageBase
}
// Extract interprets any roleResults as a Role.
func (r roleResult) Extract() (*Role, error) {
var s struct {
Role *Role `json:"role"`
}
err := r.ExtractInto(&s)
return s.Role, err
}
func (r RolePage) IsEmpty() (bool, error) {
is, err := ExtractPageRoles(r)
return len(is) == 0, err
}
func (r RolePage) NextPageURL() (string, error) {
var s struct {
Links struct {
Next string `json:"next"`
Previous string `json:"previous"`
} `json:"links"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return s.Links.Next, err
}
func ExtractPageRoles(r pagination.Page) ([]Role, error) {
var s struct {
Roles []Role `json:"roles"`
}
err := (r.(RolePage)).ExtractInto(&s)
return s.Roles, err
}