github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v3/endpoints/results.go (about) 1 package endpoints 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 type commonResult struct { 9 golangsdk.Result 10 } 11 12 // Extract interprets a GetResult, CreateResult or UpdateResult as a concrete 13 // Endpoint. An error is returned if the original call or the extraction failed. 14 func (r commonResult) Extract() (*Endpoint, error) { 15 var s struct { 16 Endpoint *Endpoint `json:"endpoint"` 17 } 18 err := r.ExtractInto(&s) 19 return s.Endpoint, err 20 } 21 22 // CreateResult is the response from a Create operation. Call its Extract 23 // method to interpret it as an Endpoint. 24 type CreateResult struct { 25 commonResult 26 } 27 28 // UpdateResult is the response from an Update operation. Call its Extract 29 // method to interpret it as an Endpoint. 30 type UpdateResult struct { 31 commonResult 32 } 33 34 // DeleteResult is the response from a Delete operation. Call its ExtractErr 35 // method to determine if the call succeeded or failed. 36 type DeleteResult struct { 37 golangsdk.ErrResult 38 } 39 40 // Endpoint describes the entry point for another service's API. 41 type Endpoint struct { 42 // ID is the unique ID of the endpoint. 43 ID string `json:"id"` 44 45 // Availability is the interface type of the Endpoint (admin, internal, 46 // or public), referenced by the golangsdk.Availability type. 47 Availability golangsdk.Availability `json:"interface"` 48 49 // Name is the name of the Endpoint. 50 Name string `json:"name"` 51 52 // Region is the region the Endpoint is located in. 53 Region string `json:"region"` 54 55 // ServiceID is the ID of the service the Endpoint refers to. 56 ServiceID string `json:"service_id"` 57 58 // URL is the url of the Endpoint. 59 URL string `json:"url"` 60 } 61 62 // EndpointPage is a single page of Endpoint results. 63 type EndpointPage struct { 64 pagination.LinkedPageBase 65 } 66 67 // IsEmpty returns true if no Endpoints were returned. 68 func (r EndpointPage) IsEmpty() (bool, error) { 69 es, err := ExtractEndpoints(r) 70 return len(es) == 0, err 71 } 72 73 // ExtractEndpoints extracts an Endpoint slice from a Page. 74 func ExtractEndpoints(r pagination.Page) ([]Endpoint, error) { 75 var s struct { 76 Endpoints []Endpoint `json:"endpoints"` 77 } 78 err := (r.(EndpointPage)).ExtractInto(&s) 79 return s.Endpoints, err 80 }