github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/elb/v3/flavors/results.go (about)

     1  package flavors
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     6  )
     7  
     8  type Flavor struct {
     9  	// Specifies the ID of the flavor.
    10  	ID string `json:"id"`
    11  
    12  	// Specifies the info of the flavor.
    13  	Info FlavorInfo `json:"info"`
    14  
    15  	// Specifies the name of the flavor.
    16  	Name string `json:"name"`
    17  
    18  	// Specifies whether shared.
    19  	Shared bool `json:"shared"`
    20  
    21  	// Specifies the type of the flavor.
    22  	Type string `json:"type"`
    23  
    24  	// Specifies whether sold out.
    25  	SoldOut bool `json:"flavor_sold_out"`
    26  }
    27  
    28  type FlavorInfo struct {
    29  	// Specifies the connection
    30  	Connection int `json:"connection"`
    31  
    32  	// Specifies the cps.
    33  	Cps int `json:"cps"`
    34  
    35  	// Specifies the qps
    36  	Qps int `json:"qps"`
    37  
    38  	// Specifies the https_cps
    39  	HttpsCps int `json:"https_cps"`
    40  
    41  	// Specifies the lcu
    42  	Lcu int `json:"lcu"`
    43  
    44  	// Specifies the bandwidth
    45  	Bandwidth int `json:"bandwidth"`
    46  }
    47  
    48  // FlavorPage is the page returned by a pager when traversing over a
    49  // collection of flavor.
    50  type FlavorPage struct {
    51  	pagination.PageWithInfo
    52  }
    53  
    54  // IsEmpty checks whether a FlavorsPage struct is empty.
    55  func (r FlavorPage) IsEmpty() (bool, error) {
    56  	is, err := ExtractFlavors(r)
    57  	return len(is) == 0, err
    58  }
    59  
    60  // ExtractFlavors accepts a Page struct, specifically a FlavorsPage struct,
    61  // and extracts the elements into a slice of flavor structs. In other words,
    62  // a generic collection is mapped into a relevant slice.
    63  func ExtractFlavors(r pagination.Page) ([]Flavor, error) {
    64  	var s []Flavor
    65  	err := (r.(FlavorPage)).ExtractIntoSlicePtr(&s, "flavors")
    66  	if err != nil {
    67  		return nil, err
    68  	}
    69  	return s, nil
    70  }
    71  
    72  type GetResult struct {
    73  	golangsdk.Result
    74  }
    75  
    76  func (r GetResult) Extract() (*Flavor, error) {
    77  	s := new(Flavor)
    78  	err := r.ExtractIntoStructPtr(s, "flavor")
    79  	if err != nil {
    80  		return nil, err
    81  	}
    82  	return s, nil
    83  }