blob: 4d7bfbcaf3f405ed572e87ae4c3e2f3ff103065e [file] [log] [blame]
Ash Wilsonbdfc3302014-09-04 10:16:28 -04001package endpoints
2
Ash Wilson700d13a2014-09-05 14:24:16 -04003import (
Ash Wilson700d13a2014-09-05 14:24:16 -04004 "github.com/mitchellh/mapstructure"
5 "github.com/rackspace/gophercloud"
6)
Ash Wilsonbdfc3302014-09-04 10:16:28 -04007
8// Endpoint describes the entry point for another service's API.
9type Endpoint struct {
Ash Wilson6269f252014-09-12 14:33:56 -040010 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 Wilsonbdfc3302014-09-04 10:16:28 -040016}
17
Ash Wilson6269f252014-09-12 14:33:56 -040018// ExtractEndpoints extracts an Endpoint slice from a Page.
19func ExtractEndpoints(page gophercloud.Page) ([]Endpoint, error) {
20 var response struct {
21 Endpoints []Endpoint `mapstructure:"endpoints"`
Ash Wilson700d13a2014-09-05 14:24:16 -040022 }
23
Ash Wilson6269f252014-09-12 14:33:56 -040024 err := mapstructure.Decode(page.(gophercloud.LinkedPage).Body, &response)
Ash Wilson700d13a2014-09-05 14:24:16 -040025 if err != nil {
26 return nil, err
27 }
Ash Wilson6269f252014-09-12 14:33:56 -040028 return response.Endpoints, nil
Ash Wilson0555c642014-09-05 16:57:17 -040029}