Ash Wilson | 70dfe0c | 2014-08-28 13:57:09 -0400 | [diff] [blame] | 1 | package gophercloud |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | ) |
| 6 | |
Ash Wilson | d5f2f2d | 2014-08-28 14:28:28 -0400 | [diff] [blame] | 7 | // ServiceClient stores details about a specific service that are necessary for further interactions with that service API, as well |
| 8 | // as utility methods for service implementation. |
Ash Wilson | 70dfe0c | 2014-08-28 13:57:09 -0400 | [diff] [blame] | 9 | // |
Ash Wilson | d5f2f2d | 2014-08-28 14:28:28 -0400 | [diff] [blame] | 10 | // Generally, you will acquire a ServiceClient by calling the NewClient() function in the appropriate service package. |
Ash Wilson | 70dfe0c | 2014-08-28 13:57:09 -0400 | [diff] [blame] | 11 | type ServiceClient struct { |
Ash Wilson | d5f2f2d | 2014-08-28 14:28:28 -0400 | [diff] [blame] | 12 | |
| 13 | // Authority caches results of the most recent authentication. |
| 14 | Authority AuthResults |
| 15 | |
| 16 | // Options remembers the original authentication parameters, if reauthentication is enabled. |
| 17 | Options AuthOptions |
| 18 | |
| 19 | // Endpoint is the base URL of the relevant API. |
| 20 | Endpoint string |
| 21 | |
| 22 | // TokenID is the most recently valid token issued. |
| 23 | TokenID string |
Ash Wilson | 70dfe0c | 2014-08-28 13:57:09 -0400 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | // ServiceURL constructs a URL for a resource belonging to this client. |
| 27 | func (client *ServiceClient) ServiceURL(parts ...string) string { |
Ash Wilson | d5f2f2d | 2014-08-28 14:28:28 -0400 | [diff] [blame] | 28 | return client.Endpoint + strings.Join(parts, "/") |
Ash Wilson | 70dfe0c | 2014-08-28 13:57:09 -0400 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | // AuthenticatedHeaders returns a map of HTTP headers that are common for all authenticated service |
| 32 | // requests. |
| 33 | func (client *ServiceClient) AuthenticatedHeaders() map[string]string { |
Ash Wilson | d5f2f2d | 2014-08-28 14:28:28 -0400 | [diff] [blame] | 34 | return map[string]string{"X-Auth-Token": client.TokenID} |
Ash Wilson | 70dfe0c | 2014-08-28 13:57:09 -0400 | [diff] [blame] | 35 | } |