...

Source file src/github.com/Azure/azure-sdk-for-go/services/dataprotection/mgmt/2021-07-01/dataprotection/operationstatus.go

Documentation: github.com/Azure/azure-sdk-for-go/services/dataprotection/mgmt/2021-07-01/dataprotection

     1  package dataprotection
     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  // OperationStatusClient is the open API 2.0 Specs for Azure Data Protection service
    18  type OperationStatusClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewOperationStatusClient creates an instance of the OperationStatusClient client.
    23  func NewOperationStatusClient(subscriptionID string) OperationStatusClient {
    24  	return NewOperationStatusClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewOperationStatusClientWithBaseURI creates an instance of the OperationStatusClient client using a custom endpoint.
    28  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewOperationStatusClientWithBaseURI(baseURI string, subscriptionID string) OperationStatusClient {
    30  	return OperationStatusClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // Get sends the get request.
    34  func (client OperationStatusClient) Get(ctx context.Context, location string, operationID string) (result OperationResource, err error) {
    35  	if tracing.IsEnabled() {
    36  		ctx = tracing.StartSpan(ctx, fqdn+"/OperationStatusClient.Get")
    37  		defer func() {
    38  			sc := -1
    39  			if result.Response.Response != nil {
    40  				sc = result.Response.Response.StatusCode
    41  			}
    42  			tracing.EndSpan(ctx, sc, err)
    43  		}()
    44  	}
    45  	req, err := client.GetPreparer(ctx, location, operationID)
    46  	if err != nil {
    47  		err = autorest.NewErrorWithError(err, "dataprotection.OperationStatusClient", "Get", nil, "Failure preparing request")
    48  		return
    49  	}
    50  
    51  	resp, err := client.GetSender(req)
    52  	if err != nil {
    53  		result.Response = autorest.Response{Response: resp}
    54  		err = autorest.NewErrorWithError(err, "dataprotection.OperationStatusClient", "Get", resp, "Failure sending request")
    55  		return
    56  	}
    57  
    58  	result, err = client.GetResponder(resp)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "dataprotection.OperationStatusClient", "Get", resp, "Failure responding to request")
    61  		return
    62  	}
    63  
    64  	return
    65  }
    66  
    67  // GetPreparer prepares the Get request.
    68  func (client OperationStatusClient) GetPreparer(ctx context.Context, location string, operationID string) (*http.Request, error) {
    69  	pathParameters := map[string]interface{}{
    70  		"location":       autorest.Encode("path", location),
    71  		"operationId":    autorest.Encode("path", operationID),
    72  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    73  	}
    74  
    75  	const APIVersion = "2021-07-01"
    76  	queryParameters := map[string]interface{}{
    77  		"api-version": APIVersion,
    78  	}
    79  
    80  	preparer := autorest.CreatePreparer(
    81  		autorest.AsGet(),
    82  		autorest.WithBaseURL(client.BaseURI),
    83  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DataProtection/locations/{location}/operationStatus/{operationId}", pathParameters),
    84  		autorest.WithQueryParameters(queryParameters))
    85  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    86  }
    87  
    88  // GetSender sends the Get request. The method will close the
    89  // http.Response Body if it receives an error.
    90  func (client OperationStatusClient) GetSender(req *http.Request) (*http.Response, error) {
    91  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
    92  }
    93  
    94  // GetResponder handles the response to the Get request. The method always
    95  // closes the http.Response Body.
    96  func (client OperationStatusClient) GetResponder(resp *http.Response) (result OperationResource, err error) {
    97  	err = autorest.Respond(
    98  		resp,
    99  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   100  		autorest.ByUnmarshallingJSON(&result),
   101  		autorest.ByClosing())
   102  	result.Response = autorest.Response{Response: resp}
   103  	return
   104  }
   105  

View as plain text