github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v2/extensions/admin/roles/results.go (about) 1 package roles 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // Role represents an API role resource. 9 type Role struct { 10 // ID is the unique ID for the role. 11 ID string 12 13 // Name is the human-readable name of the role. 14 Name string 15 16 // Description is the description of the role. 17 Description string 18 19 // ServiceID is the associated service for this role. 20 ServiceID string 21 } 22 23 // RolePage is a single page of a user Role collection. 24 type RolePage struct { 25 pagination.SinglePageBase 26 } 27 28 // IsEmpty determines whether or not a page of Roles contains any results. 29 func (r RolePage) IsEmpty() (bool, error) { 30 users, err := ExtractRoles(r) 31 return len(users) == 0, err 32 } 33 34 // ExtractRoles returns a slice of roles contained in a single page of results. 35 func ExtractRoles(r pagination.Page) ([]Role, error) { 36 var s struct { 37 Roles []Role `json:"roles"` 38 } 39 err := (r.(RolePage)).ExtractInto(&s) 40 return s.Roles, err 41 } 42 43 // UserRoleResult represents the result of either an AddUserRole or 44 // a DeleteUserRole operation. Call its ExtractErr method to determine 45 // if the request succeeded or failed. 46 type UserRoleResult struct { 47 golangsdk.ErrResult 48 }