github.com/gophercloud/gophercloud@v1.11.0/openstack/db/v1/databases/results.go (about) 1 package databases 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // Database represents a Database API resource. 9 type Database struct { 10 // Specifies the name of the MySQL database. 11 Name string 12 13 // Set of symbols and encodings. The default character set is utf8. 14 CharSet string 15 16 // Set of rules for comparing characters in a character set. The default 17 // value for collate is utf8_general_ci. 18 Collate string 19 } 20 21 // CreateResult represents the result of a Create operation. 22 type CreateResult struct { 23 gophercloud.ErrResult 24 } 25 26 // DeleteResult represents the result of a Delete operation. 27 type DeleteResult struct { 28 gophercloud.ErrResult 29 } 30 31 // DBPage represents a single page of a paginated DB collection. 32 type DBPage struct { 33 pagination.LinkedPageBase 34 } 35 36 // IsEmpty checks to see whether the collection is empty. 37 func (page DBPage) IsEmpty() (bool, error) { 38 if page.StatusCode == 204 { 39 return true, nil 40 } 41 42 dbs, err := ExtractDBs(page) 43 return len(dbs) == 0, err 44 } 45 46 // NextPageURL will retrieve the next page URL. 47 func (page DBPage) NextPageURL() (string, error) { 48 var s struct { 49 Links []gophercloud.Link `json:"databases_links"` 50 } 51 err := page.ExtractInto(&s) 52 if err != nil { 53 return "", err 54 } 55 return gophercloud.ExtractNextURL(s.Links) 56 } 57 58 // ExtractDBs will convert a generic pagination struct into a more 59 // relevant slice of DB structs. 60 func ExtractDBs(page pagination.Page) ([]Database, error) { 61 r := page.(DBPage) 62 var s struct { 63 Databases []Database `json:"databases"` 64 } 65 err := r.ExtractInto(&s) 66 return s.Databases, err 67 }