...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-01-01/backup/operations.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-01-01/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  // OperationsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type OperationsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewOperationsClient creates an instance of the OperationsClient client.
    23  func NewOperationsClient(subscriptionID string) OperationsClient {
    24  	return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewOperationsClientWithBaseURI creates an instance of the OperationsClient 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 NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient {
    30  	return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // List returns the list of available operations.
    34  func (client OperationsClient) List(ctx context.Context) (result ClientDiscoveryResponsePage, err error) {
    35  	if tracing.IsEnabled() {
    36  		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
    37  		defer func() {
    38  			sc := -1
    39  			if result.cdr.Response.Response != nil {
    40  				sc = result.cdr.Response.Response.StatusCode
    41  			}
    42  			tracing.EndSpan(ctx, sc, err)
    43  		}()
    44  	}
    45  	result.fn = client.listNextResults
    46  	req, err := client.ListPreparer(ctx)
    47  	if err != nil {
    48  		err = autorest.NewErrorWithError(err, "backup.OperationsClient", "List", nil, "Failure preparing request")
    49  		return
    50  	}
    51  
    52  	resp, err := client.ListSender(req)
    53  	if err != nil {
    54  		result.cdr.Response = autorest.Response{Response: resp}
    55  		err = autorest.NewErrorWithError(err, "backup.OperationsClient", "List", resp, "Failure sending request")
    56  		return
    57  	}
    58  
    59  	result.cdr, err = client.ListResponder(resp)
    60  	if err != nil {
    61  		err = autorest.NewErrorWithError(err, "backup.OperationsClient", "List", resp, "Failure responding to request")
    62  		return
    63  	}
    64  	if result.cdr.hasNextLink() && result.cdr.IsEmpty() {
    65  		err = result.NextWithContext(ctx)
    66  		return
    67  	}
    68  
    69  	return
    70  }
    71  
    72  // ListPreparer prepares the List request.
    73  func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
    74  	const APIVersion = "2016-08-10"
    75  	queryParameters := map[string]interface{}{
    76  		"api-version": APIVersion,
    77  	}
    78  
    79  	preparer := autorest.CreatePreparer(
    80  		autorest.AsGet(),
    81  		autorest.WithBaseURL(client.BaseURI),
    82  		autorest.WithPath("/providers/Microsoft.RecoveryServices/operations"),
    83  		autorest.WithQueryParameters(queryParameters))
    84  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    85  }
    86  
    87  // ListSender sends the List request. The method will close the
    88  // http.Response Body if it receives an error.
    89  func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) {
    90  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    91  }
    92  
    93  // ListResponder handles the response to the List request. The method always
    94  // closes the http.Response Body.
    95  func (client OperationsClient) ListResponder(resp *http.Response) (result ClientDiscoveryResponse, err error) {
    96  	err = autorest.Respond(
    97  		resp,
    98  		azure.WithErrorUnlessStatusCode(http.StatusOK),
    99  		autorest.ByUnmarshallingJSON(&result),
   100  		autorest.ByClosing())
   101  	result.Response = autorest.Response{Response: resp}
   102  	return
   103  }
   104  
   105  // listNextResults retrieves the next set of results, if any.
   106  func (client OperationsClient) listNextResults(ctx context.Context, lastResults ClientDiscoveryResponse) (result ClientDiscoveryResponse, err error) {
   107  	req, err := lastResults.clientDiscoveryResponsePreparer(ctx)
   108  	if err != nil {
   109  		return result, autorest.NewErrorWithError(err, "backup.OperationsClient", "listNextResults", nil, "Failure preparing next results request")
   110  	}
   111  	if req == nil {
   112  		return
   113  	}
   114  	resp, err := client.ListSender(req)
   115  	if err != nil {
   116  		result.Response = autorest.Response{Response: resp}
   117  		return result, autorest.NewErrorWithError(err, "backup.OperationsClient", "listNextResults", resp, "Failure sending next results request")
   118  	}
   119  	result, err = client.ListResponder(resp)
   120  	if err != nil {
   121  		err = autorest.NewErrorWithError(err, "backup.OperationsClient", "listNextResults", resp, "Failure responding to next results request")
   122  	}
   123  	return
   124  }
   125  
   126  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   127  func (client OperationsClient) ListComplete(ctx context.Context) (result ClientDiscoveryResponseIterator, err error) {
   128  	if tracing.IsEnabled() {
   129  		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
   130  		defer func() {
   131  			sc := -1
   132  			if result.Response().Response.Response != nil {
   133  				sc = result.page.Response().Response.Response.StatusCode
   134  			}
   135  			tracing.EndSpan(ctx, sc, err)
   136  		}()
   137  	}
   138  	result.page, err = client.List(ctx)
   139  	return
   140  }
   141  

View as plain text