github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v2/extensions/delegate.go (about)

     1  package extensions
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	common "github.com/huaweicloud/golangsdk/openstack/common/extensions"
     6  	"github.com/huaweicloud/golangsdk/pagination"
     7  )
     8  
     9  // ExtensionPage is a single page of Extension results.
    10  type ExtensionPage struct {
    11  	common.ExtensionPage
    12  }
    13  
    14  // IsEmpty returns true if the current page contains at least one Extension.
    15  func (page ExtensionPage) IsEmpty() (bool, error) {
    16  	is, err := ExtractExtensions(page)
    17  	return len(is) == 0, err
    18  }
    19  
    20  // ExtractExtensions accepts a Page struct, specifically an ExtensionPage struct, and extracts the
    21  // elements into a slice of Extension structs.
    22  func ExtractExtensions(page pagination.Page) ([]common.Extension, error) {
    23  	// Identity v2 adds an intermediate "values" object.
    24  	var s struct {
    25  		Extensions struct {
    26  			Values []common.Extension `json:"values"`
    27  		} `json:"extensions"`
    28  	}
    29  	err := page.(ExtensionPage).ExtractInto(&s)
    30  	return s.Extensions.Values, err
    31  }
    32  
    33  // Get retrieves information for a specific extension using its alias.
    34  func Get(c *golangsdk.ServiceClient, alias string) common.GetResult {
    35  	return common.Get(c, alias)
    36  }
    37  
    38  // List returns a Pager which allows you to iterate over the full collection of extensions.
    39  // It does not accept query parameters.
    40  func List(c *golangsdk.ServiceClient) pagination.Pager {
    41  	return common.List(c).WithPageCreator(func(r pagination.PageResult) pagination.Page {
    42  		return ExtensionPage{
    43  			ExtensionPage: common.ExtensionPage{SinglePageBase: pagination.SinglePageBase(r)},
    44  		}
    45  	})
    46  }