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

     1  package endpointgroups
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // EndpointGroup is an endpoint group.
     9  type EndpointGroup struct {
    10  	// TenantID specifies a tenant to own the endpoint group.
    11  	TenantID string `json:"tenant_id"`
    12  
    13  	// TenantID specifies a tenant to own the endpoint group.
    14  	ProjectID string `json:"project_id"`
    15  
    16  	// Description is the human readable description of the endpoint group.
    17  	Description string `json:"description"`
    18  
    19  	// Name is the human readable name of the endpoint group.
    20  	Name string `json:"name"`
    21  
    22  	// Type is the type of the endpoints in the group.
    23  	Type string `json:"type"`
    24  
    25  	// Endpoints is a list of endpoints.
    26  	Endpoints []string `json:"endpoints"`
    27  
    28  	// ID is the id of the endpoint group
    29  	ID string `json:"id"`
    30  }
    31  
    32  type commonResult struct {
    33  	gophercloud.Result
    34  }
    35  
    36  // Extract is a function that accepts a result and extracts an endpoint group.
    37  func (r commonResult) Extract() (*EndpointGroup, error) {
    38  	var s struct {
    39  		Service *EndpointGroup `json:"endpoint_group"`
    40  	}
    41  	err := r.ExtractInto(&s)
    42  	return s.Service, err
    43  }
    44  
    45  // EndpointGroupPage is the page returned by a pager when traversing over a
    46  // collection of Policies.
    47  type EndpointGroupPage struct {
    48  	pagination.LinkedPageBase
    49  }
    50  
    51  // NextPageURL is invoked when a paginated collection of Endpoint groups has
    52  // reached the end of a page and the pager seeks to traverse over a new one.
    53  // In order to do this, it needs to construct the next page's URL.
    54  func (r EndpointGroupPage) NextPageURL() (string, error) {
    55  	var s struct {
    56  		Links []gophercloud.Link `json:"endpoint_groups_links"`
    57  	}
    58  	err := r.ExtractInto(&s)
    59  	if err != nil {
    60  		return "", err
    61  	}
    62  	return gophercloud.ExtractNextURL(s.Links)
    63  }
    64  
    65  // IsEmpty checks whether an EndpointGroupPage struct is empty.
    66  func (r EndpointGroupPage) IsEmpty() (bool, error) {
    67  	if r.StatusCode == 204 {
    68  		return true, nil
    69  	}
    70  
    71  	is, err := ExtractEndpointGroups(r)
    72  	return len(is) == 0, err
    73  }
    74  
    75  // ExtractEndpointGroups accepts a Page struct, specifically an EndpointGroupPage struct,
    76  // and extracts the elements into a slice of Endpoint group structs. In other words,
    77  // a generic collection is mapped into a relevant slice.
    78  func ExtractEndpointGroups(r pagination.Page) ([]EndpointGroup, error) {
    79  	var s struct {
    80  		EndpointGroups []EndpointGroup `json:"endpoint_groups"`
    81  	}
    82  	err := (r.(EndpointGroupPage)).ExtractInto(&s)
    83  	return s.EndpointGroups, err
    84  }
    85  
    86  // CreateResult represents the result of a create operation. Call its Extract
    87  // method to interpret it as an endpoint group.
    88  type CreateResult struct {
    89  	commonResult
    90  }
    91  
    92  // GetResult represents the result of a get operation. Call its Extract
    93  // method to interpret it as an EndpointGroup.
    94  type GetResult struct {
    95  	commonResult
    96  }
    97  
    98  // DeleteResult represents the results of a Delete operation. Call its ExtractErr method
    99  // to determine whether the operation succeeded or failed.
   100  type DeleteResult struct {
   101  	gophercloud.ErrResult
   102  }
   103  
   104  // UpdateResult represents the result of an update operation. Call its Extract method
   105  // to interpret it as an EndpointGroup.
   106  type UpdateResult struct {
   107  	commonResult
   108  }