...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2019-06-15/backup/operation.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2019-06-15/backup

     1  package backup
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/tracing"
    14  	"net/http"
    15  )
    16  
    17  // OperationClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type OperationClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewOperationClient creates an instance of the OperationClient client.
    23  func NewOperationClient(subscriptionID string) OperationClient {
    24  	return NewOperationClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewOperationClientWithBaseURI creates an instance of the OperationClient client using a custom endpoint.  Use this
    28  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewOperationClientWithBaseURI(baseURI string, subscriptionID string) OperationClient {
    30  	return OperationClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // Validate validate operation for specified backed up item. This is a synchronous operation.
    34  // Parameters:
    35  // vaultName - the name of the recovery services vault.
    36  // resourceGroupName - the name of the resource group where the recovery services vault is present.
    37  // parameters - resource validate operation request
    38  func (client OperationClient) Validate(ctx context.Context, vaultName string, resourceGroupName string, parameters BasicValidateOperationRequest) (result ValidateOperationsResponse, err error) {
    39  	if tracing.IsEnabled() {
    40  		ctx = tracing.StartSpan(ctx, fqdn+"/OperationClient.Validate")
    41  		defer func() {
    42  			sc := -1
    43  			if result.Response.Response != nil {
    44  				sc = result.Response.Response.StatusCode
    45  			}
    46  			tracing.EndSpan(ctx, sc, err)
    47  		}()
    48  	}
    49  	req, err := client.ValidatePreparer(ctx, vaultName, resourceGroupName, parameters)
    50  	if err != nil {
    51  		err = autorest.NewErrorWithError(err, "backup.OperationClient", "Validate", nil, "Failure preparing request")
    52  		return
    53  	}
    54  
    55  	resp, err := client.ValidateSender(req)
    56  	if err != nil {
    57  		result.Response = autorest.Response{Response: resp}
    58  		err = autorest.NewErrorWithError(err, "backup.OperationClient", "Validate", resp, "Failure sending request")
    59  		return
    60  	}
    61  
    62  	result, err = client.ValidateResponder(resp)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "backup.OperationClient", "Validate", resp, "Failure responding to request")
    65  		return
    66  	}
    67  
    68  	return
    69  }
    70  
    71  // ValidatePreparer prepares the Validate request.
    72  func (client OperationClient) ValidatePreparer(ctx context.Context, vaultName string, resourceGroupName string, parameters BasicValidateOperationRequest) (*http.Request, error) {
    73  	pathParameters := map[string]interface{}{
    74  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    75  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    76  		"vaultName":         autorest.Encode("path", vaultName),
    77  	}
    78  
    79  	const APIVersion = "2019-06-15"
    80  	queryParameters := map[string]interface{}{
    81  		"api-version": APIVersion,
    82  	}
    83  
    84  	preparer := autorest.CreatePreparer(
    85  		autorest.AsContentType("application/json; charset=utf-8"),
    86  		autorest.AsPost(),
    87  		autorest.WithBaseURL(client.BaseURI),
    88  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupValidateOperation", pathParameters),
    89  		autorest.WithJSON(parameters),
    90  		autorest.WithQueryParameters(queryParameters))
    91  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    92  }
    93  
    94  // ValidateSender sends the Validate request. The method will close the
    95  // http.Response Body if it receives an error.
    96  func (client OperationClient) ValidateSender(req *http.Request) (*http.Response, error) {
    97  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
    98  }
    99  
   100  // ValidateResponder handles the response to the Validate request. The method always
   101  // closes the http.Response Body.
   102  func (client OperationClient) ValidateResponder(resp *http.Response) (result ValidateOperationsResponse, err error) {
   103  	err = autorest.Respond(
   104  		resp,
   105  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   106  		autorest.ByUnmarshallingJSON(&result),
   107  		autorest.ByClosing())
   108  	result.Response = autorest.Response{Response: resp}
   109  	return
   110  }
   111  

View as plain text