github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/imageservice/v2/members/results.go (about)

     1  package members
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/huaweicloud/golangsdk"
     7  	"github.com/huaweicloud/golangsdk/pagination"
     8  )
     9  
    10  // Member represents a member of an Image.
    11  type Member struct {
    12  	CreatedAt time.Time `json:"created_at"`
    13  	ImageID   string    `json:"image_id"`
    14  	MemberID  string    `json:"member_id"`
    15  	Schema    string    `json:"schema"`
    16  	Status    string    `json:"status"`
    17  	UpdatedAt time.Time `json:"updated_at"`
    18  }
    19  
    20  // Extract Member model from a request.
    21  func (r commonResult) Extract() (*Member, error) {
    22  	var s *Member
    23  	err := r.ExtractInto(&s)
    24  	return s, err
    25  }
    26  
    27  // MemberPage is a single page of Members results.
    28  type MemberPage struct {
    29  	pagination.SinglePageBase
    30  }
    31  
    32  // ExtractMembers returns a slice of Members contained in a single page
    33  // of results.
    34  func ExtractMembers(r pagination.Page) ([]Member, error) {
    35  	var s struct {
    36  		Members []Member `json:"members"`
    37  	}
    38  	err := r.(MemberPage).ExtractInto(&s)
    39  	return s.Members, err
    40  }
    41  
    42  // IsEmpty determines whether or not a MemberPage contains any results.
    43  func (r MemberPage) IsEmpty() (bool, error) {
    44  	members, err := ExtractMembers(r)
    45  	return len(members) == 0, err
    46  }
    47  
    48  type commonResult struct {
    49  	golangsdk.Result
    50  }
    51  
    52  // CreateResult represents the result of a Create operation. Call its Extract
    53  // method to interpret it as a Member.
    54  type CreateResult struct {
    55  	commonResult
    56  }
    57  
    58  // DetailsResult represents the result of a Get operation. Call its Extract
    59  // method to interpret it as a Member.
    60  type DetailsResult struct {
    61  	commonResult
    62  }
    63  
    64  // UpdateResult represents the result of an Update operation. Call its Extract
    65  // method to interpret it as a Member.
    66  type UpdateResult struct {
    67  	commonResult
    68  }
    69  
    70  // DeleteResult represents the result of a Delete operation. Call its
    71  // ExtractErr method to determine if the request succeeded or failed.
    72  type DeleteResult struct {
    73  	golangsdk.ErrResult
    74  }