blob: 66a297b2aeaf70988125e499b6ae6076778f8098 [file] [log] [blame]
Ash Wilson6425a412014-08-29 12:30:35 -04001package gophercloud
2
3import "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.
7type ServiceClient struct {
Ash Wilson55bbaaf2014-10-22 09:06:46 -04008 // ProviderClient is a reference to the provider that implements this service.
9 *ProviderClient
Ash Wilson6425a412014-08-29 12:30:35 -040010
11 // Endpoint is the base URL of the service's API, acquired from a service catalog.
Ash Wilsoned6a1d82014-09-03 12:01:00 -040012 // It MUST end with a /.
Ash Wilson6425a412014-08-29 12:30:35 -040013 Endpoint string
Ash Wilson42380322014-10-06 14:21:46 -040014
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
Jon Perrittc0dd8e52016-03-10 01:20:27 -060019
20 Microversion string
Ash Wilson42380322014-10-06 14:21:46 -040021}
22
23// ResourceBaseURL returns the base URL of any resources used by this service. It MUST end with a /.
24func (client *ServiceClient) ResourceBaseURL() string {
25 if client.ResourceBase != "" {
26 return client.ResourceBase
27 }
28 return client.Endpoint
Ash Wilson6425a412014-08-29 12:30:35 -040029}
30
31// ServiceURL constructs a URL for a resource belonging to this provider.
32func (client *ServiceClient) ServiceURL(parts ...string) string {
Ash Wilson42380322014-10-06 14:21:46 -040033 return client.ResourceBaseURL() + strings.Join(parts, "/")
34}