github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/vpnaas/endpointgroups/results.go (about) 1 package endpointgroups 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/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 golangsdk.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 []golangsdk.Link `json:"endpoint_groups_links"` 57 } 58 err := r.ExtractInto(&s) 59 if err != nil { 60 return "", err 61 } 62 return golangsdk.ExtractNextURL(s.Links) 63 } 64 65 // IsEmpty checks whether an EndpointGroupPage struct is empty. 66 func (r EndpointGroupPage) IsEmpty() (bool, error) { 67 is, err := ExtractEndpointGroups(r) 68 return len(is) == 0, err 69 } 70 71 // ExtractEndpointGroups accepts a Page struct, specifically an EndpointGroupPage struct, 72 // and extracts the elements into a slice of Endpoint group structs. In other words, 73 // a generic collection is mapped into a relevant slice. 74 func ExtractEndpointGroups(r pagination.Page) ([]EndpointGroup, error) { 75 var s struct { 76 EndpointGroups []EndpointGroup `json:"endpoint_groups"` 77 } 78 err := (r.(EndpointGroupPage)).ExtractInto(&s) 79 return s.EndpointGroups, err 80 } 81 82 // CreateResult represents the result of a create operation. Call its Extract 83 // method to interpret it as an endpoint group. 84 type CreateResult struct { 85 commonResult 86 } 87 88 // GetResult represents the result of a get operation. Call its Extract 89 // method to interpret it as an EndpointGroup. 90 type GetResult struct { 91 commonResult 92 } 93 94 // DeleteResult represents the results of a Delete operation. Call its ExtractErr method 95 // to determine whether the operation succeeded or failed. 96 type DeleteResult struct { 97 golangsdk.ErrResult 98 } 99 100 // UpdateResult represents the result of an update operation. Call its Extract method 101 // to interpret it as an EndpointGroup. 102 type UpdateResult struct { 103 commonResult 104 }