Jamie Hannaford | 8c072a3 | 2014-10-16 14:33:32 +0200 | [diff] [blame] | 1 | package gophercloud |
| 2 | |
| 3 | import "strings" |
| 4 | |
| 5 | // ServiceClient stores details required to interact with a specific service API implemented by a provider. |
| 6 | // Generally, you'll acquire these by calling the appropriate `New` method on a ProviderClient. |
| 7 | type ServiceClient struct { |
| 8 | // Provider is a reference to the provider that implements this service. |
| 9 | Provider *ProviderClient |
| 10 | |
| 11 | // Endpoint is the base URL of the service's API, acquired from a service catalog. |
| 12 | // It MUST end with a /. |
| 13 | Endpoint string |
| 14 | |
| 15 | // ResourceBase is the base URL shared by the resources within a service's API. It should include |
| 16 | // the API version and, like Endpoint, MUST end with a / if set. If not set, the Endpoint is used |
| 17 | // as-is, instead. |
| 18 | ResourceBase string |
| 19 | } |
| 20 | |
| 21 | // ResourceBaseURL returns the base URL of any resources used by this service. It MUST end with a /. |
| 22 | func (client *ServiceClient) ResourceBaseURL() string { |
| 23 | if client.ResourceBase != "" { |
| 24 | return client.ResourceBase |
| 25 | } |
| 26 | return client.Endpoint |
| 27 | } |
| 28 | |
| 29 | // ServiceURL constructs a URL for a resource belonging to this provider. |
| 30 | func (client *ServiceClient) ServiceURL(parts ...string) string { |
| 31 | return client.ResourceBaseURL() + strings.Join(parts, "/") |
| 32 | } |
| 33 | |
| 34 | // AuthenticatedHeaders returns a collection of HTTP request headers that mark a request as |
| 35 | // belonging to the currently authenticated user. |
| 36 | func (client *ServiceClient) AuthenticatedHeaders() map[string]string { |
| 37 | return client.Provider.AuthenticatedHeaders() |
| 38 | } |