Ash Wilson | bdfc330 | 2014-09-04 10:16:28 -0400 | [diff] [blame] | 1 | package endpoints |
| 2 | |
Ash Wilson | 700d13a | 2014-09-05 14:24:16 -0400 | [diff] [blame] | 3 | import ( |
Ash Wilson | 700d13a | 2014-09-05 14:24:16 -0400 | [diff] [blame] | 4 | "github.com/mitchellh/mapstructure" |
| 5 | "github.com/rackspace/gophercloud" |
| 6 | ) |
Ash Wilson | bdfc330 | 2014-09-04 10:16:28 -0400 | [diff] [blame] | 7 | |
| 8 | // Endpoint describes the entry point for another service's API. |
| 9 | type Endpoint struct { |
Ash Wilson | 6269f25 | 2014-09-12 14:33:56 -0400 | [diff] [blame^] | 10 | ID string `mapstructure:"id" json:"id"` |
| 11 | Availability gophercloud.Availability `mapstructure:"interface" json:"interface"` |
| 12 | Name string `mapstructure:"name" json:"name"` |
| 13 | Region string `mapstructure:"region" json:"region"` |
| 14 | ServiceID string `mapstructure:"service_id" json:"service_id"` |
| 15 | URL string `mapstructure:"url" json:"url"` |
Ash Wilson | bdfc330 | 2014-09-04 10:16:28 -0400 | [diff] [blame] | 16 | } |
| 17 | |
Ash Wilson | 6269f25 | 2014-09-12 14:33:56 -0400 | [diff] [blame^] | 18 | // ExtractEndpoints extracts an Endpoint slice from a Page. |
| 19 | func ExtractEndpoints(page gophercloud.Page) ([]Endpoint, error) { |
| 20 | var response struct { |
| 21 | Endpoints []Endpoint `mapstructure:"endpoints"` |
Ash Wilson | 700d13a | 2014-09-05 14:24:16 -0400 | [diff] [blame] | 22 | } |
| 23 | |
Ash Wilson | 6269f25 | 2014-09-12 14:33:56 -0400 | [diff] [blame^] | 24 | err := mapstructure.Decode(page.(gophercloud.LinkedPage).Body, &response) |
Ash Wilson | 700d13a | 2014-09-05 14:24:16 -0400 | [diff] [blame] | 25 | if err != nil { |
| 26 | return nil, err |
| 27 | } |
Ash Wilson | 6269f25 | 2014-09-12 14:33:56 -0400 | [diff] [blame^] | 28 | return response.Endpoints, nil |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame] | 29 | } |