github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/blockstorage/v1/apiversions/results.go (about)

     1  package apiversions
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // APIVersion represents an API version for Cinder.
     9  type APIVersion struct {
    10  	ID      string `json:"id"`      // unique identifier
    11  	Status  string `json:"status"`  // current status
    12  	Updated string `json:"updated"` // date last updated
    13  }
    14  
    15  // APIVersionPage is the page returned by a pager when traversing over a
    16  // collection of API versions.
    17  type APIVersionPage struct {
    18  	pagination.SinglePageBase
    19  }
    20  
    21  // IsEmpty checks whether an APIVersionPage struct is empty.
    22  func (r APIVersionPage) IsEmpty() (bool, error) {
    23  	is, err := ExtractAPIVersions(r)
    24  	return len(is) == 0, err
    25  }
    26  
    27  // ExtractAPIVersions takes a collection page, extracts all of the elements,
    28  // and returns them a slice of APIVersion structs. It is effectively a cast.
    29  func ExtractAPIVersions(r pagination.Page) ([]APIVersion, error) {
    30  	var s struct {
    31  		Versions []APIVersion `json:"versions"`
    32  	}
    33  	err := (r.(APIVersionPage)).ExtractInto(&s)
    34  	return s.Versions, err
    35  }
    36  
    37  // GetResult represents the result of a get operation.
    38  type GetResult struct {
    39  	golangsdk.Result
    40  }
    41  
    42  // Extract is a function that accepts a result and extracts an API version resource.
    43  func (r GetResult) Extract() (*APIVersion, error) {
    44  	var s struct {
    45  		Version *APIVersion `json:"version"`
    46  	}
    47  	err := r.ExtractInto(&s)
    48  	return s.Version, err
    49  }