Ash Wilson | b73b7f8 | 2014-08-29 15:38:06 -0400 | [diff] [blame] | 1 | package services |
| 2 | |
Ash Wilson | 64f4415 | 2014-09-05 13:45:03 -0400 | [diff] [blame] | 3 | import ( |
Ash Wilson | bddac13 | 2014-09-12 14:20:16 -0400 | [diff] [blame^] | 4 | "github.com/rackspace/gophercloud" |
Ash Wilson | 2f5dd1f | 2014-09-03 14:01:37 -0400 | [diff] [blame] | 5 | |
Ash Wilson | 64f4415 | 2014-09-05 13:45:03 -0400 | [diff] [blame] | 6 | "github.com/mitchellh/mapstructure" |
Ash Wilson | 64f4415 | 2014-09-05 13:45:03 -0400 | [diff] [blame] | 7 | ) |
| 8 | |
| 9 | // Service is the result of a list or information query. |
| 10 | type Service struct { |
Ash Wilson | b73b7f8 | 2014-08-29 15:38:06 -0400 | [diff] [blame] | 11 | Description *string `json:"description,omitempty"` |
| 12 | ID string `json:"id"` |
| 13 | Name string `json:"name"` |
| 14 | Type string `json:"type"` |
| 15 | } |
Ash Wilson | 2f5dd1f | 2014-09-03 14:01:37 -0400 | [diff] [blame] | 16 | |
Ash Wilson | bddac13 | 2014-09-12 14:20:16 -0400 | [diff] [blame^] | 17 | // ExtractServices extracts a slice of Services from a Collection acquired from List. |
| 18 | func ExtractServices(page gophercloud.Page) ([]Service, error) { |
| 19 | var response struct { |
| 20 | Services []Service `mapstructure:"services"` |
Ash Wilson | 64f4415 | 2014-09-05 13:45:03 -0400 | [diff] [blame] | 21 | } |
| 22 | |
Ash Wilson | bddac13 | 2014-09-12 14:20:16 -0400 | [diff] [blame^] | 23 | err := mapstructure.Decode(page.(gophercloud.LinkedPage).Body, &response) |
| 24 | return response.Services, err |
Ash Wilson | 2f5dd1f | 2014-09-03 14:01:37 -0400 | [diff] [blame] | 25 | } |