github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/elb/v3/flavors/results.go (about)

     1  package flavors
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk/pagination"
     5  )
     6  
     7  type Flavor struct {
     8  	// Specifies the ID of the flavor.
     9  	ID string `json:"id"`
    10  
    11  	// Specifies the info of the flavor.
    12  	Info FlavorInfo `json:"info"`
    13  
    14  	// Specifies the name of the flavor.
    15  	Name string `json:"name"`
    16  
    17  	// Specifies whether shared.
    18  	Shared bool `json:"shared"`
    19  
    20  	// Specifies the type of the flavor.
    21  	Type string `json:"type"`
    22  
    23  	// Specifies whether sold out.
    24  	SoldOut bool `json:"flavor_sold_out"`
    25  }
    26  
    27  type FlavorInfo struct {
    28  	// Specifies the connection
    29  	Connection int `json:"connection"`
    30  
    31  	// Specifies the cps.
    32  	Cps int `json:"cps"`
    33  
    34  	// Specifies the qps
    35  	Qps int `json:"qps"`
    36  
    37  	// Specifies the bandwidth
    38  	Bandwidth int `json:"bandwidth"`
    39  }
    40  
    41  // FlavorsPage is the page returned by a pager when traversing over a
    42  // collection of flavor.
    43  type FlavorsPage struct {
    44  	pagination.LinkedPageBase
    45  }
    46  
    47  // IsEmpty checks whether a FlavorsPage struct is empty.
    48  func (r FlavorsPage) IsEmpty() (bool, error) {
    49  	is, err := ExtractFlavors(r)
    50  	return len(is) == 0, err
    51  }
    52  
    53  // ExtractFlavors accepts a Page struct, specifically a FlavorsPage struct,
    54  // and extracts the elements into a slice of flavor structs. In other words,
    55  // a generic collection is mapped into a relevant slice.
    56  func ExtractFlavors(r pagination.Page) ([]Flavor, error) {
    57  	var s struct {
    58  		Flavors []Flavor `json:"flavors"`
    59  	}
    60  	err := (r.(FlavorsPage)).ExtractInto(&s)
    61  	return s.Flavors, err
    62  }