本文整理汇总了Golang中github.com/Azure/azure-sdk-for-go/arm/storage.AccountsClient.CheckNameAvailability方法的典型用法代码示例。如果您正苦于以下问题:Golang AccountsClient.CheckNameAvailability方法的具体用法?Golang AccountsClient.CheckNameAvailability怎么用?Golang AccountsClient.CheckNameAvailability使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Azure/azure-sdk-for-go/arm/storage.AccountsClient
的用法示例。
在下文中一共展示了AccountsClient.CheckNameAvailability方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createStorageAccount
func createStorageAccount(
client storage.AccountsClient,
accountType storage.AccountType,
resourceGroup string,
location string,
tags map[string]string,
accountNameGenerator func() string,
) (string, string, error) {
logger.Debugf("creating storage account (finding available name)")
const maxAttempts = 10
for remaining := maxAttempts; remaining > 0; remaining-- {
accountName := accountNameGenerator()
logger.Debugf("- checking storage account name %q", accountName)
result, err := client.CheckNameAvailability(
storage.AccountCheckNameAvailabilityParameters{
Name: to.StringPtr(accountName),
// Azure is a little inconsistent with when Type is
// required. It's required here.
Type: to.StringPtr("Microsoft.Storage/storageAccounts"),
},
)
if err != nil {
return "", "", errors.Annotate(err, "checking account name availability")
}
if !to.Bool(result.NameAvailable) {
logger.Debugf(
"%q is not available (%v): %v",
accountName, result.Reason, result.Message,
)
continue
}
createParams := storage.AccountCreateParameters{
Location: to.StringPtr(location),
Tags: toTagsPtr(tags),
Properties: &storage.AccountPropertiesCreateParameters{
AccountType: accountType,
},
}
logger.Debugf("- creating %q storage account %q", accountType, accountName)
// TODO(axw) account creation can fail if the account name is
// available, but contains profanity. We should retry a set
// number of times even if creating fails.
if _, err := client.Create(resourceGroup, accountName, createParams); err != nil {
return "", "", errors.Trace(err)
}
logger.Debugf("- listing storage account keys")
listKeysResult, err := client.ListKeys(resourceGroup, accountName)
if err != nil {
return "", "", errors.Annotate(err, "listing storage account keys")
}
return accountName, to.String(listKeysResult.Key1), nil
}
return "", "", errors.New("could not find available storage account name")
}