github.com/gophercloud/gophercloud@v1.11.0/openstack/clustering/v1/profiletypes/results.go (about)

     1  package profiletypes
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // commonResult is the response of a base result.
     9  type commonResult struct {
    10  	gophercloud.Result
    11  }
    12  
    13  // GetResult is the response of a Get operations.
    14  type GetResult struct {
    15  	commonResult
    16  }
    17  
    18  type Schema map[string]interface{}
    19  type SupportStatus map[string]interface{}
    20  
    21  type ProfileType struct {
    22  	Name          string                     `json:"name"`
    23  	Schema        map[string]Schema          `json:"schema"`
    24  	SupportStatus map[string][]SupportStatus `json:"support_status"`
    25  }
    26  
    27  func (r commonResult) Extract() (*ProfileType, error) {
    28  	var s struct {
    29  		ProfileType *ProfileType `json:"profile_type"`
    30  	}
    31  	err := r.ExtractInto(&s)
    32  	return s.ProfileType, err
    33  }
    34  
    35  // ExtractProfileTypes provides access to the list of profiles in a page acquired from the List operation.
    36  func ExtractProfileTypes(r pagination.Page) ([]ProfileType, error) {
    37  	var s struct {
    38  		ProfileTypes []ProfileType `json:"profile_types"`
    39  	}
    40  	err := (r.(ProfileTypePage)).ExtractInto(&s)
    41  	return s.ProfileTypes, err
    42  }
    43  
    44  // ProfileTypePage contains a single page of all profiles from a List call.
    45  type ProfileTypePage struct {
    46  	pagination.LinkedPageBase
    47  }
    48  
    49  // IsEmpty determines if ExtractProfileTypes contains any results.
    50  func (page ProfileTypePage) IsEmpty() (bool, error) {
    51  	if page.StatusCode == 204 {
    52  		return true, nil
    53  	}
    54  
    55  	profileTypes, err := ExtractProfileTypes(page)
    56  	return len(profileTypes) == 0, err
    57  }
    58  
    59  // OperationPage contains a single page of all profile type operations from a ListOps call.
    60  type OperationPage struct {
    61  	pagination.SinglePageBase
    62  }
    63  
    64  // ExtractOps provides access to the list of operations in a page acquired from the ListOps operation.
    65  func ExtractOps(r pagination.Page) (map[string]interface{}, error) {
    66  	var s struct {
    67  		Operations map[string]interface{} `json:"operations"`
    68  	}
    69  	err := (r.(OperationPage)).ExtractInto(&s)
    70  	return s.Operations, err
    71  }