~jtv/gwacl/require-storage-location

« back to all changes in this revision

Viewing changes to storage_base.go

  • Committer: jtv at canonical
  • Date: 2013-08-06 11:11:50 UTC
  • Revision ID: jtv@canonical.com-20130806111150-6ky59l9v5e6yunfv
Make StorageContext.AzureEndpoint required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
210
210
    Key string
211
211
 
212
212
    // AzureEndpoint specifies a base service endpoint URL for the Azure APIs.
213
 
    // If this is not set, it will default to the international endpoint which
214
 
    // will not work in mainland China.
215
 
    //
216
 
    // Try to set this if at all possible.  Use GetEndpoint() to obtain the
217
 
    // endpoint associated with a given service location, e.g. "West US" or
218
 
    // "North Europe" or "East China".
 
213
    // This field is required.
219
214
    AzureEndpoint APIEndpoint
220
215
 
221
216
    client *http.Client
334
329
// getAccountURL returns the base URL for the context's storage account.
335
330
// (The result ends in a slash.)
336
331
func (context *StorageContext) getAccountURL() string {
337
 
    endpoint := context.AzureEndpoint
338
 
    if endpoint == "" {
339
 
        // No API endpoint specified.  Default to the international one.
340
 
        // This will not work for mainland China.
341
 
        // TODO: Make this required, and panic() instead.
342
 
        endpoint = GetEndpoint("West US")
 
332
    if context.AzureEndpoint == APIEndpoint("") {
 
333
        panic(errors.New("no Azure blob storage endpoint specified"))
343
334
    }
344
 
    return endpoint.BlobStorageAPI(context.Account)
 
335
    return context.AzureEndpoint.BlobStorageAPI(context.Account)
345
336
}
346
337
 
347
338
// getContainerURL returns the URL for a given storage container.
348
339
// (The result does not end in a slash.)
349
340
func (context *StorageContext) getContainerURL(container string) string {
350
 
    return context.getAccountURL() + url.QueryEscape(container)
 
341
    return strings.TrimRight(context.getAccountURL(), "/") + "/" + url.QueryEscape(container)
351
342
}
352
343
 
353
344
// GetFileURL returns the URL for a given file in the given container.