forked from gophercloud/gophercloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.go
48 lines (39 loc) · 1.17 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
package roles
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// Role represents an API role resource.
type Role struct {
// ID is the unique ID for the role.
ID string
// Name is the human-readable name of the role.
Name string
// Description is the description of the role.
Description string
// ServiceID is the associated service for this role.
ServiceID string
}
// RolePage is a single page of a user Role collection.
type RolePage struct {
pagination.SinglePageBase
}
// IsEmpty determines whether or not a page of Roles contains any results.
func (r RolePage) IsEmpty() (bool, error) {
users, err := ExtractRoles(r)
return len(users) == 0, err
}
// ExtractRoles returns a slice of roles contained in a single page of results.
func ExtractRoles(r pagination.Page) ([]Role, error) {
var s struct {
Roles []Role `json:"roles"`
}
err := (r.(RolePage)).ExtractInto(&s)
return s.Roles, err
}
// UserRoleResult represents the result of either an AddUserRole or
// a DeleteUserRole operation. Call its ExtractErr method to determine
// if the request succeeded or failed.
type UserRoleResult struct {
gophercloud.ErrResult
}