github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/db/v1/datastores/results.go (about) 1 package datastores 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // Version represents a version API resource. Multiple versions belong to a Datastore. 9 type Version struct { 10 ID string 11 Links []golangsdk.Link 12 Name string 13 } 14 15 // Datastore represents a Datastore API resource. 16 type Datastore struct { 17 DefaultVersion string `json:"default_version"` 18 ID string 19 Links []golangsdk.Link 20 Name string 21 Versions []Version 22 } 23 24 // DatastorePartial is a meta structure which is used in various API responses. 25 // It is a lightweight and truncated version of a full Datastore resource, 26 // offering details of the Version, Type and VersionID only. 27 type DatastorePartial struct { 28 Version string 29 Type string 30 VersionID string `json:"version_id"` 31 } 32 33 // GetResult represents the result of a Get operation. 34 type GetResult struct { 35 golangsdk.Result 36 } 37 38 // GetVersionResult represents the result of getting a version. 39 type GetVersionResult struct { 40 golangsdk.Result 41 } 42 43 // DatastorePage represents a page of datastore resources. 44 type DatastorePage struct { 45 pagination.SinglePageBase 46 } 47 48 // IsEmpty indicates whether a Datastore collection is empty. 49 func (r DatastorePage) IsEmpty() (bool, error) { 50 is, err := ExtractDatastores(r) 51 return len(is) == 0, err 52 } 53 54 // ExtractDatastores retrieves a slice of datastore structs from a paginated 55 // collection. 56 func ExtractDatastores(r pagination.Page) ([]Datastore, error) { 57 var s struct { 58 Datastores []Datastore `json:"datastores"` 59 } 60 err := (r.(DatastorePage)).ExtractInto(&s) 61 return s.Datastores, err 62 } 63 64 // Extract retrieves a single Datastore struct from an operation result. 65 func (r GetResult) Extract() (*Datastore, error) { 66 var s struct { 67 Datastore *Datastore `json:"datastore"` 68 } 69 err := r.ExtractInto(&s) 70 return s.Datastore, err 71 } 72 73 // VersionPage represents a page of version resources. 74 type VersionPage struct { 75 pagination.SinglePageBase 76 } 77 78 // IsEmpty indicates whether a collection of version resources is empty. 79 func (r VersionPage) IsEmpty() (bool, error) { 80 is, err := ExtractVersions(r) 81 return len(is) == 0, err 82 } 83 84 // ExtractVersions retrieves a slice of versions from a paginated collection. 85 func ExtractVersions(r pagination.Page) ([]Version, error) { 86 var s struct { 87 Versions []Version `json:"versions"` 88 } 89 err := (r.(VersionPage)).ExtractInto(&s) 90 return s.Versions, err 91 } 92 93 // Extract retrieves a single Version struct from an operation result. 94 func (r GetVersionResult) Extract() (*Version, error) { 95 var s struct { 96 Version *Version `json:"version"` 97 } 98 err := r.ExtractInto(&s) 99 return s.Version, err 100 }