github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/lbaas/members/results.go (about)

     1  package members
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/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 []gophercloud.Link `json:"members_links"`
    49  	}
    50  	err := r.ExtractInto(&s)
    51  	if err != nil {
    52  		return "", err
    53  	}
    54  	return gophercloud.ExtractNextURL(s.Links)
    55  }
    56  
    57  // IsEmpty checks whether a MemberPage struct is empty.
    58  func (r MemberPage) IsEmpty() (bool, error) {
    59  	if r.StatusCode == 204 {
    60  		return true, nil
    61  	}
    62  
    63  	is, err := ExtractMembers(r)
    64  	return len(is) == 0, err
    65  }
    66  
    67  // ExtractMembers accepts a Page struct, specifically a MemberPage struct,
    68  // and extracts the elements into a slice of Member structs. In other words,
    69  // a generic collection is mapped into a relevant slice.
    70  func ExtractMembers(r pagination.Page) ([]Member, error) {
    71  	var s struct {
    72  		Members []Member `json:"members"`
    73  	}
    74  	err := (r.(MemberPage)).ExtractInto(&s)
    75  	return s.Members, err
    76  }
    77  
    78  type commonResult struct {
    79  	gophercloud.Result
    80  }
    81  
    82  // Extract is a function that accepts a result and extracts a member.
    83  func (r commonResult) Extract() (*Member, error) {
    84  	var s struct {
    85  		Member *Member `json:"member"`
    86  	}
    87  	err := r.ExtractInto(&s)
    88  	return s.Member, err
    89  }
    90  
    91  // CreateResult represents the result of a create operation. Call its Extract
    92  // method to interpret it as a Member.
    93  type CreateResult struct {
    94  	commonResult
    95  }
    96  
    97  // GetResult represents the result of a get operation. Call its Extract
    98  // method to interpret it as a Member.
    99  type GetResult struct {
   100  	commonResult
   101  }
   102  
   103  // UpdateResult represents the result of an update operation. Call its Extract
   104  // method to interpret it as a Member.
   105  type UpdateResult struct {
   106  	commonResult
   107  }
   108  
   109  // DeleteResult represents the result of a delete operation. Call its
   110  // ExtractErr method to determine if the result succeeded or failed.
   111  type DeleteResult struct {
   112  	gophercloud.ErrResult
   113  }