github.com/gophercloud/gophercloud@v1.11.0/openstack/identity/v3/endpoints/results.go (about)

     1  package endpoints
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  type commonResult struct {
     9  	gophercloud.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  	gophercloud.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 gophercloud.Availability type.
    47  	Availability gophercloud.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  	// Enabled is whether or not the endpoint is enabled.
    62  	Enabled bool `json:"enabled"`
    63  }
    64  
    65  // EndpointPage is a single page of Endpoint results.
    66  type EndpointPage struct {
    67  	pagination.LinkedPageBase
    68  }
    69  
    70  // IsEmpty returns true if no Endpoints were returned.
    71  func (r EndpointPage) IsEmpty() (bool, error) {
    72  	if r.StatusCode == 204 {
    73  		return true, nil
    74  	}
    75  
    76  	es, err := ExtractEndpoints(r)
    77  	return len(es) == 0, err
    78  }
    79  
    80  // ExtractEndpoints extracts an Endpoint slice from a Page.
    81  func ExtractEndpoints(r pagination.Page) ([]Endpoint, error) {
    82  	var s struct {
    83  		Endpoints []Endpoint `json:"endpoints"`
    84  	}
    85  	err := (r.(EndpointPage)).ExtractInto(&s)
    86  	return s.Endpoints, err
    87  }