本文整理匯總了Golang中github.com/Azure/go-autorest/autorest.WithErrorUnlessOK函數的典型用法代碼示例。如果您正苦於以下問題:Golang WithErrorUnlessOK函數的具體用法?Golang WithErrorUnlessOK怎麽用?Golang WithErrorUnlessOK使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了WithErrorUnlessOK函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: refreshInternal
func (spt *ServicePrincipalToken) refreshInternal(resource string) error {
v := url.Values{}
v.Set("client_id", spt.clientID)
v.Set("resource", resource)
if spt.RefreshToken != "" {
v.Set("grant_type", OAuthGrantTypeRefreshToken)
v.Set("refresh_token", spt.RefreshToken)
} else {
v.Set("grant_type", OAuthGrantTypeClientCredentials)
err := spt.secret.SetAuthenticationValues(spt, &v)
if err != nil {
return err
}
}
req, _ := autorest.Prepare(&http.Request{},
autorest.AsPost(),
autorest.AsFormURLEncoded(),
autorest.WithBaseURL(spt.oauthConfig.TokenEndpoint.String()),
autorest.WithFormData(v))
resp, err := autorest.SendWithSender(spt.sender, req)
if err != nil {
return autorest.NewErrorWithError(err,
"azure.ServicePrincipalToken", "Refresh", resp, "Failure sending request for Service Principal %s",
spt.clientID)
}
var newToken Token
err = autorest.Respond(resp,
autorest.WithErrorUnlessOK(),
autorest.ByUnmarshallingJSON(&newToken),
autorest.ByClosing())
if err != nil {
return autorest.NewErrorWithError(err,
"azure.ServicePrincipalToken", "Refresh", resp, "Failure handling response to Service Principal %s request",
spt.clientID)
}
spt.Token = newToken
err = spt.InvokeRefreshCallbacks(newToken)
if err != nil {
// its already wrapped inside InvokeRefreshCallbacks
return err
}
return nil
}
示例2: Refresh
// Refresh obtains a fresh token for the Service Principal.
func (spt *ServicePrincipalToken) Refresh() error {
p := map[string]interface{}{
"tenantID": spt.tenantID,
"requestType": "token",
}
v := url.Values{}
v.Set("client_id", spt.clientID)
v.Set("grant_type", "client_credentials")
v.Set("resource", spt.resource)
err := spt.secret.SetAuthenticationValues(spt, &v)
if err != nil {
return err
}
req, err := autorest.Prepare(&http.Request{},
autorest.AsPost(),
autorest.AsFormURLEncoded(),
autorest.WithBaseURL(oauthURL),
autorest.WithPathParameters(p),
autorest.WithFormData(v))
if err != nil {
return err
}
resp, err := autorest.SendWithSender(spt.sender, req)
if err != nil {
return autorest.NewErrorWithError(err,
"azure.ServicePrincipalToken", "Refresh", "Failure sending request for Service Principal %s",
spt.clientID)
}
var newToken Token
err = autorest.Respond(resp,
autorest.WithErrorUnlessOK(),
autorest.ByUnmarshallingJSON(&newToken),
autorest.ByClosing())
if err != nil {
return autorest.NewErrorWithError(err,
"azure.ServicePrincipalToken", "Refresh", "Failure handling response to Service Principal %s request",
spt.clientID)
}
spt.Token = newToken
return nil
}
示例3: CreateOrUpdate
// CreateOrUpdate create a resource group.
//
// resourceGroupName is the name of the resource group to be created or
// updated. parameters is parameters supplied to the create or update
// resource group service operation.
func (client ResourceGroupsClient) CreateOrUpdate(resourceGroupName string, parameters ResourceGroup) (result ResourceGroup, ae autorest.Error) {
req, err := client.NewCreateOrUpdateRequest(resourceGroupName, parameters)
if err != nil {
return result, autorest.NewErrorWithError(err, "resources.ResourceGroupsClient", "CreateOrUpdate", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "resources.ResourceGroupsClient", "CreateOrUpdate", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusCreated, http.StatusOK, http.StatusAccepted))
if err == nil {
err = client.IsPollingAllowed(resp)
if err == nil {
resp, err = client.PollAsNeeded(resp)
}
}
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK(),
autorest.ByUnmarshallingJSON(&result))
if err != nil {
ae = autorest.NewErrorWithError(err, "resources.ResourceGroupsClient", "CreateOrUpdate", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "resources.ResourceGroupsClient", "CreateOrUpdate", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
示例4: Capture
// Capture captures the VM by copying VirtualHardDisks of the VM and outputs a
// template that can be used to create similar VMs.
//
// resourceGroupName is the name of the resource group. vmName is the name of
// the virtual machine. parameters is parameters supplied to the Capture
// Virtual Machine operation.
func (client VirtualMachinesClient) Capture(resourceGroupName string, vmName string, parameters VirtualMachineCaptureParameters) (result ComputeLongRunningOperationResult, ae autorest.Error) {
req, err := client.NewCaptureRequest(resourceGroupName, vmName, parameters)
if err != nil {
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "Capture", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "Capture", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted))
if err == nil {
err = client.IsPollingAllowed(resp)
if err == nil {
resp, err = client.PollAsNeeded(resp)
}
}
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK(),
autorest.ByUnmarshallingJSON(&result))
if err != nil {
ae = autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "Capture", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "Capture", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
示例5: Start
// Start the operation to start a virtual machine.
//
// resourceGroupName is the name of the resource group. vmName is the name of
// the virtual machine.
func (client VirtualMachinesClient) Start(resourceGroupName string, vmName string) (result autorest.Response, ae autorest.Error) {
req, err := client.NewStartRequest(resourceGroupName, vmName)
if err != nil {
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "Start", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "Start", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusAccepted))
if err == nil {
err = client.IsPollingAllowed(resp)
if err == nil {
resp, err = client.PollAsNeeded(resp)
}
}
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK())
if err != nil {
ae = autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "Start", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "compute.VirtualMachinesClient", "Start", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = resp
return
}
示例6: Delete
// Delete the Delete LocalNetworkGateway operation deletes the specifed local
// network Gateway through Network resource provider.
//
// resourceGroupName is the name of the resource group.
// localNetworkGatewayName is the name of the local network gateway.
func (client LocalNetworkGatewaysClient) Delete(resourceGroupName string, localNetworkGatewayName string) (result autorest.Response, ae autorest.Error) {
req, err := client.NewDeleteRequest(resourceGroupName, localNetworkGatewayName)
if err != nil {
return result, autorest.NewErrorWithError(err, "network.LocalNetworkGatewaysClient", "Delete", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "network.LocalNetworkGatewaysClient", "Delete", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusAccepted, http.StatusNoContent, http.StatusOK))
if err == nil {
err = client.IsPollingAllowed(resp)
if err == nil {
resp, err = client.PollAsNeeded(resp)
}
}
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK())
if err != nil {
ae = autorest.NewErrorWithError(err, "network.LocalNetworkGatewaysClient", "Delete", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "network.LocalNetworkGatewaysClient", "Delete", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = resp
return
}
示例7: MoveResources
// MoveResources move resources within or across subscriptions.
//
// sourceResourceGroupName is source resource group name. parameters is move
// resources' parameters.
func (client ResourcesClient) MoveResources(sourceResourceGroupName string, parameters ResourcesMoveInfo) (result autorest.Response, ae autorest.Error) {
req, err := client.NewMoveResourcesRequest(sourceResourceGroupName, parameters)
if err != nil {
return result, autorest.NewErrorWithError(err, "resources.ResourcesClient", "MoveResources", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "resources.ResourcesClient", "MoveResources", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusAccepted))
if err == nil {
err = client.IsPollingAllowed(resp)
if err == nil {
resp, err = client.PollAsNeeded(resp)
}
}
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK())
if err != nil {
ae = autorest.NewErrorWithError(err, "resources.ResourcesClient", "MoveResources", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "resources.ResourcesClient", "MoveResources", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = resp
return
}
示例8: DeleteAtSubscriptionLevel
// DeleteAtSubscriptionLevel deletes the management lock of a subscription.
//
// lockName is the name of lock.
func (client ManagementLocksClient) DeleteAtSubscriptionLevel(lockName string) (result autorest.Response, ae autorest.Error) {
req, err := client.NewDeleteAtSubscriptionLevelRequest(lockName)
if err != nil {
return result, autorest.NewErrorWithError(err, "authorization.ManagementLocksClient", "DeleteAtSubscriptionLevel", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "authorization.ManagementLocksClient", "DeleteAtSubscriptionLevel", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK, http.StatusAccepted))
if err == nil {
err = client.IsPollingAllowed(resp)
if err == nil {
resp, err = client.PollAsNeeded(resp)
}
}
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK())
if err != nil {
ae = autorest.NewErrorWithError(err, "authorization.ManagementLocksClient", "DeleteAtSubscriptionLevel", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "authorization.ManagementLocksClient", "DeleteAtSubscriptionLevel", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = resp
return
}
示例9: Delete
// Delete delete resource and all of its resources.
//
// resourceGroupName is the name of the resource group. The name is case
// insensitive. resourceProviderNamespace is resource identity.
// parentResourcePath is resource identity. resourceType is resource
// identity. resourceName is resource identity.
func (client ResourcesClient) Delete(resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, apiVersion string) (result autorest.Response, ae autorest.Error) {
req, err := client.NewDeleteRequest(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion)
if err != nil {
return result, autorest.NewErrorWithError(err, "resources.ResourcesClient", "Delete", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "resources.ResourcesClient", "Delete", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent, http.StatusAccepted))
if err == nil {
err = client.IsPollingAllowed(resp)
if err == nil {
resp, err = client.PollAsNeeded(resp)
}
}
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK())
if err != nil {
ae = autorest.NewErrorWithError(err, "resources.ResourcesClient", "Delete", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "resources.ResourcesClient", "Delete", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = resp
return
}
示例10: ListAtSubscriptionLevel
// ListAtSubscriptionLevel gets all the management locks of a subscription.
//
// filter is the filter to apply on the operation.
func (client ManagementLocksClient) ListAtSubscriptionLevel(filter string) (result ManagementLockListResult, ae autorest.Error) {
req, err := client.NewListAtSubscriptionLevelRequest(filter)
if err != nil {
return result, autorest.NewErrorWithError(err, "authorization.ManagementLocksClient", "ListAtSubscriptionLevel", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "authorization.ManagementLocksClient", "ListAtSubscriptionLevel", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusOK))
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK(),
autorest.ByUnmarshallingJSON(&result))
if err != nil {
ae = autorest.NewErrorWithError(err, "authorization.ManagementLocksClient", "ListAtSubscriptionLevel", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "authorization.ManagementLocksClient", "ListAtSubscriptionLevel", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
示例11: List
// List gets a list of resource providers.
//
// resourceProviderNamespace is resource identity.
func (client ResourceProviderOperationDetailsClient) List(resourceProviderNamespace string, apiVersion string) (result ResourceProviderOperationDetailListResult, ae autorest.Error) {
req, err := client.NewListRequest(resourceProviderNamespace, apiVersion)
if err != nil {
return result, autorest.NewErrorWithError(err, "resources.ResourceProviderOperationDetailsClient", "List", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "resources.ResourceProviderOperationDetailsClient", "List", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent))
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK(),
autorest.ByUnmarshallingJSON(&result))
if err != nil {
ae = autorest.NewErrorWithError(err, "resources.ResourceProviderOperationDetailsClient", "List", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "resources.ResourceProviderOperationDetailsClient", "List", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
示例12: Get
// Get get a deployment.
//
// resourceGroupName is the name of the resource group to get. The name is
// case insensitive. deploymentName is the name of the deployment.
func (client DeploymentsClient) Get(resourceGroupName string, deploymentName string) (result DeploymentExtended, ae autorest.Error) {
req, err := client.NewGetRequest(resourceGroupName, deploymentName)
if err != nil {
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "Get", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "resources.DeploymentsClient", "Get", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusOK))
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK(),
autorest.ByUnmarshallingJSON(&result))
if err != nil {
ae = autorest.NewErrorWithError(err, "resources.DeploymentsClient", "Get", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "resources.DeploymentsClient", "Get", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
示例13: Get
// Get gets details about particular subscription.
//
// subscriptionId is id of the subscription.
func (client SubscriptionsClient) Get(subscriptionId string) (result Subscription, ae autorest.Error) {
req, err := client.NewGetRequest(subscriptionId)
if err != nil {
return result, autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "Get", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "Get", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusOK))
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK(),
autorest.ByUnmarshallingJSON(&result))
if err != nil {
ae = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "Get", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "Get", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
示例14: CreateOrUpdate
// CreateOrUpdate provisions a new job collection or updates an existing job
// collection.
//
// resourceGroupName is the resource group name. jobCollectionName is the job
// collection name. jobCollection is the job collection definition.
func (client JobCollectionsClient) CreateOrUpdate(resourceGroupName string, jobCollectionName string, jobCollection JobCollectionDefinition) (result JobCollectionDefinition, ae autorest.Error) {
req, err := client.NewCreateOrUpdateRequest(resourceGroupName, jobCollectionName, jobCollection)
if err != nil {
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "CreateOrUpdate", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "CreateOrUpdate", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusOK, http.StatusCreated))
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK(),
autorest.ByUnmarshallingJSON(&result))
if err != nil {
ae = autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "CreateOrUpdate", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "scheduler.JobCollectionsClient", "CreateOrUpdate", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
示例15: CheckNameAvailability
// CheckNameAvailability checks that account name is valid and is not in use.
//
// accountName is the name of the storage account within the specified
// resource group. Storage account names must be between 3 and 24 characters
// in length and use numbers and lower-case letters only.
func (client StorageAccountsClient) CheckNameAvailability(accountName StorageAccountCheckNameAvailabilityParameters) (result CheckNameAvailabilityResult, ae autorest.Error) {
req, err := client.NewCheckNameAvailabilityRequest(accountName)
if err != nil {
return result, autorest.NewErrorWithError(err, "storage.StorageAccountsClient", "CheckNameAvailability", "Failure creating request")
}
req, err = autorest.Prepare(
req,
client.WithAuthorization(),
client.WithInspection())
if err != nil {
return result, autorest.NewErrorWithError(err, "storage.StorageAccountsClient", "CheckNameAvailability", "Failure preparing request")
}
resp, err := autorest.SendWithSender(
client,
req,
autorest.DoErrorUnlessStatusCode(http.StatusOK))
if err == nil {
err = autorest.Respond(
resp,
client.ByInspecting(),
autorest.WithErrorUnlessOK(),
autorest.ByUnmarshallingJSON(&result))
if err != nil {
ae = autorest.NewErrorWithError(err, "storage.StorageAccountsClient", "CheckNameAvailability", "Failure responding to request")
}
} else {
ae = autorest.NewErrorWithError(err, "storage.StorageAccountsClient", "CheckNameAvailability", "Failure sending request")
}
autorest.Respond(resp,
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}