github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v3/catalog/results.go (about) 1 package catalog 2 3 import ( 4 "github.com/huaweicloud/golangsdk/openstack/identity/v3/tokens" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // CatalogPage is a single page of Service results. 9 type CatalogPage struct { 10 pagination.LinkedPageBase 11 } 12 13 // IsEmpty returns true if the CatalogPage contains no results. 14 func (p CatalogPage) IsEmpty() (bool, error) { 15 services, err := ExtractServiceCatalog(p) 16 return len(services) == 0, err 17 } 18 19 // NextPageURL extracts the "next" link from the links section of the result. 20 func (r CatalogPage) NextPageURL() (string, error) { 21 var s struct { 22 Links struct { 23 Next string `json:"next"` 24 Previous string `json:"previous"` 25 } `json:"links"` 26 } 27 err := r.ExtractInto(&s) 28 if err != nil { 29 return "", err 30 } 31 return s.Links.Next, err 32 } 33 34 // ExtractServiceCatalog extracts a slice of Catalog from a Collection acquired 35 // from List. 36 func ExtractServiceCatalog(r pagination.Page) ([]tokens.CatalogEntry, error) { 37 var s struct { 38 Entries []tokens.CatalogEntry `json:"catalog"` 39 } 40 err := (r.(CatalogPage)).ExtractInto(&s) 41 return s.Entries, err 42 }