Jamie Hannaford | 4721abc | 2014-09-16 16:29:04 +0200 | [diff] [blame^] | 1 | package apiversions |
| 2 | |
| 3 | import ( |
| 4 | "github.com/mitchellh/mapstructure" |
| 5 | "github.com/rackspace/gophercloud" |
| 6 | ) |
| 7 | |
| 8 | type APIVersion struct { |
| 9 | Status string `mapstructure:"status" json:"status"` |
| 10 | ID string `mapstructure:"id" json:"id"` |
| 11 | } |
| 12 | |
| 13 | func ExtractAPIVersions(page gophercloud.Page) ([]APIVersion, error) { |
| 14 | var resp struct { |
| 15 | Versions []APIVersion `mapstructure:"versions"` |
| 16 | } |
| 17 | |
| 18 | err := mapstructure.Decode(page.(gophercloud.LinkedPage).Body, &resp) |
| 19 | if err != nil { |
| 20 | return nil, err |
| 21 | } |
| 22 | |
| 23 | return resp.Versions, nil |
| 24 | } |
| 25 | |
| 26 | type APIVersionResource struct { |
| 27 | Name string `mapstructure:"name" json:"name"` |
| 28 | Collection string `mapstructure:"collection" json:"collection"` |
| 29 | } |
| 30 | |
| 31 | func ExtractVersionResources(page gophercloud.Page) ([]APIVersionResource, error) { |
| 32 | var resp struct { |
| 33 | APIVersionResources []APIVersionResource `mapstructure:"resources"` |
| 34 | } |
| 35 | |
| 36 | err := mapstructure.Decode(page.(gophercloud.LinkedPage).Body, &resp) |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | |
| 41 | return resp.APIVersionResources, nil |
| 42 | } |