| package gophercloud |
| |
| import "strings" |
| |
| // ServiceClient stores details required to interact with a specific service API implemented by a provider. |
| // Generally, you'll acquire these by calling the appropriate `New` method on a ProviderClient. |
| type ServiceClient struct { |
| // Provider is a reference to the provider that implements this service. |
| Provider *ProviderClient |
| |
| // Endpoint is the base URL of the service's API, acquired from a service catalog. |
| // It MUST end with a /. |
| Endpoint string |
| |
| // ResourceBase is the base URL shared by the resources within a service's API. It should include |
| // the API version and, like Endpoint, MUST end with a / if set. If not set, the Endpoint is used |
| // as-is, instead. |
| ResourceBase string |
| } |
| |
| // ResourceBaseURL returns the base URL of any resources used by this service. It MUST end with a /. |
| func (client *ServiceClient) ResourceBaseURL() string { |
| if client.ResourceBase != "" { |
| return client.ResourceBase |
| } |
| return client.Endpoint |
| } |
| |
| // ServiceURL constructs a URL for a resource belonging to this provider. |
| func (client *ServiceClient) ServiceURL(parts ...string) string { |
| return client.ResourceBaseURL() + strings.Join(parts, "/") |
| } |
| |
| // AuthenticatedHeaders returns a collection of HTTP request headers that mark a request as |
| // belonging to the currently authenticated user. |
| func (client *ServiceClient) AuthenticatedHeaders() map[string]string { |
| return client.Provider.AuthenticatedHeaders() |
| } |