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

     1  package members
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // Member represents the application running on a backend server.
     9  type Member struct {
    10  	// Status is the status of the member. Indicates whether the member
    11  	// is operational.
    12  	Status string
    13  
    14  	// Weight is the weight of member.
    15  	Weight int
    16  
    17  	// AdminStateUp is the administrative state of the member, which is up
    18  	// (true) or down (false).
    19  	AdminStateUp bool `json:"admin_state_up"`
    20  
    21  	// TenantID is the owner of the member.
    22  	TenantID string `json:"tenant_id"`
    23  
    24  	// PoolID is the pool to which the member belongs.
    25  	PoolID string `json:"pool_id"`
    26  
    27  	// Address is the IP address of the member.
    28  	Address string
    29  
    30  	// ProtocolPort is the port on which the application is hosted.
    31  	ProtocolPort int `json:"protocol_port"`
    32  
    33  	// ID is the unique ID for the member.
    34  	ID string
    35  }
    36  
    37  // MemberPage is the page returned by a pager when traversing over a
    38  // collection of pool members.
    39  type MemberPage struct {
    40  	pagination.LinkedPageBase
    41  }
    42  
    43  // NextPageURL is invoked when a paginated collection of members has reached
    44  // the end of a page and the pager seeks to traverse over a new one. In order
    45  // to do this, it needs to construct the next page's URL.
    46  func (r MemberPage) NextPageURL() (string, error) {
    47  	var s struct {
    48  		Links []golangsdk.Link `json:"members_links"`
    49  	}
    50  	err := r.ExtractInto(&s)
    51  	if err != nil {
    52  		return "", err
    53  	}
    54  	return golangsdk.ExtractNextURL(s.Links)
    55  }
    56  
    57  // IsEmpty checks whether a MemberPage struct is empty.
    58  func (r MemberPage) IsEmpty() (bool, error) {
    59  	is, err := ExtractMembers(r)
    60  	return len(is) == 0, err
    61  }
    62  
    63  // ExtractMembers accepts a Page struct, specifically a MemberPage struct,
    64  // and extracts the elements into a slice of Member structs. In other words,
    65  // a generic collection is mapped into a relevant slice.
    66  func ExtractMembers(r pagination.Page) ([]Member, error) {
    67  	var s struct {
    68  		Members []Member `json:"members"`
    69  	}
    70  	err := (r.(MemberPage)).ExtractInto(&s)
    71  	return s.Members, err
    72  }
    73  
    74  type commonResult struct {
    75  	golangsdk.Result
    76  }
    77  
    78  // Extract is a function that accepts a result and extracts a member.
    79  func (r commonResult) Extract() (*Member, error) {
    80  	var s struct {
    81  		Member *Member `json:"member"`
    82  	}
    83  	err := r.ExtractInto(&s)
    84  	return s.Member, err
    85  }
    86  
    87  // CreateResult represents the result of a create operation. Call its Extract
    88  // method to interpret it as a Member.
    89  type CreateResult struct {
    90  	commonResult
    91  }
    92  
    93  // GetResult represents the result of a get operation. Call its Extract
    94  // method to interpret it as a Member.
    95  type GetResult struct {
    96  	commonResult
    97  }
    98  
    99  // UpdateResult represents the result of an update operation. Call its Extract
   100  // method to interpret it as a Member.
   101  type UpdateResult struct {
   102  	commonResult
   103  }
   104  
   105  // DeleteResult represents the result of a delete operation. Call its
   106  // ExtractErr method to determine if the result succeeded or failed.
   107  type DeleteResult struct {
   108  	golangsdk.ErrResult
   109  }