github.com/gophercloud/gophercloud@v1.11.0/openstack/identity/v2/extensions/admin/roles/results.go (about)

     1  package roles
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/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  	if r.StatusCode == 204 {
    31  		return true, nil
    32  	}
    33  
    34  	users, err := ExtractRoles(r)
    35  	return len(users) == 0, err
    36  }
    37  
    38  // ExtractRoles returns a slice of roles contained in a single page of results.
    39  func ExtractRoles(r pagination.Page) ([]Role, error) {
    40  	var s struct {
    41  		Roles []Role `json:"roles"`
    42  	}
    43  	err := (r.(RolePage)).ExtractInto(&s)
    44  	return s.Roles, err
    45  }
    46  
    47  // UserRoleResult represents the result of either an AddUserRole or
    48  // a DeleteUserRole operation. Call its ExtractErr method to determine
    49  // if the request succeeded or failed.
    50  type UserRoleResult struct {
    51  	gophercloud.ErrResult
    52  }