github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/rms/v1/resources/results.go (about) 1 package resources 2 3 import ( 4 "github.com/chnsz/golangsdk/pagination" 5 ) 6 7 type ListResp struct { 8 Resources []Resource `json:"resources"` 9 PageInfo PageInfo `json:"page_info"` 10 } 11 12 type Resource struct { 13 Id string `json:"id"` 14 Name string `json:"name"` 15 Provider string `json:"provider"` 16 Type string `json:"type"` 17 RegionId string `json:"region_id"` 18 ProjectId string `json:"project_id"` 19 ProjectName string `json:"project_name"` 20 EpId string `json:"ep_id"` 21 EpName string `json:"ep_name"` 22 Checksum string `json:"checksum"` 23 Created string `json:"created"` 24 Updated string `json:"updated"` 25 ProvisioningState string `json:"provisioning_state"` 26 Tags map[string]string `json:"tags"` 27 Properties map[string]interface{} `json:"properties"` 28 } 29 30 type PageInfo struct { 31 CurrentCount int `json:"current_count"` 32 NextMarker string `json:"next_marker"` 33 } 34 35 // ResourcePage is the page returned by a pager when traversing over a 36 // collection of route tables 37 type ResourcePage struct { 38 pagination.MarkerPageBase 39 } 40 41 // LastMarker returns the last resource ID in a ListResult 42 func (r ResourcePage) LastMarker() (string, error) { 43 var s ListResp 44 err := r.ExtractInto(&s) 45 if err != nil { 46 return "", err 47 } 48 return s.PageInfo.NextMarker, nil 49 } 50 51 // IsEmpty checks whether a ResourcePage struct is empty. 52 func (r ResourcePage) IsEmpty() (bool, error) { 53 tables, err := ExtractResources(r) 54 return len(tables) == 0, err 55 } 56 57 // ExtractResources accepts a Page struct, specifically a ResourcePage struct, 58 // and extracts the elements into a slice of Resource structs. 59 func ExtractResources(r pagination.Page) ([]Resource, error) { 60 var s ListResp 61 err := (r.(ResourcePage)).ExtractInto(&s) 62 return s.Resources, err 63 }