1package siterecovery 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 9import ( 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 client for the Operations methods of the Siterecovery service. 18type OperationsClient struct { 19 BaseClient 20} 21 22// NewOperationsClient creates an instance of the OperationsClient client. 23func NewOperationsClient(subscriptionID string, resourceGroupName string, resourceName string) OperationsClient { 24 return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID, resourceGroupName, resourceName) 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). 29func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string, resourceGroupName string, resourceName string) OperationsClient { 30 return OperationsClient{NewWithBaseURI(baseURI, subscriptionID, resourceGroupName, resourceName)} 31} 32 33// List operation to return the list of available operations. 34func (client OperationsClient) List(ctx context.Context) (result OperationsDiscoveryCollectionPage, err error) { 35 if tracing.IsEnabled() { 36 ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List") 37 defer func() { 38 sc := -1 39 if result.odc.Response.Response != nil { 40 sc = result.odc.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, "siterecovery.OperationsClient", "List", nil, "Failure preparing request") 49 return 50 } 51 52 resp, err := client.ListSender(req) 53 if err != nil { 54 result.odc.Response = autorest.Response{Response: resp} 55 err = autorest.NewErrorWithError(err, "siterecovery.OperationsClient", "List", resp, "Failure sending request") 56 return 57 } 58 59 result.odc, err = client.ListResponder(resp) 60 if err != nil { 61 err = autorest.NewErrorWithError(err, "siterecovery.OperationsClient", "List", resp, "Failure responding to request") 62 return 63 } 64 if result.odc.hasNextLink() && result.odc.IsEmpty() { 65 err = result.NextWithContext(ctx) 66 return 67 } 68 69 return 70} 71 72// ListPreparer prepares the List request. 73func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { 74 pathParameters := map[string]interface{}{ 75 "resourceGroupName": autorest.Encode("path", client.ResourceGroupName), 76 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 77 } 78 79 const APIVersion = "2016-08-10" 80 queryParameters := map[string]interface{}{ 81 "api-version": APIVersion, 82 } 83 84 preparer := autorest.CreatePreparer( 85 autorest.AsGet(), 86 autorest.WithBaseURL(client.BaseURI), 87 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/operations", pathParameters), 88 autorest.WithQueryParameters(queryParameters)) 89 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 90} 91 92// ListSender sends the List request. The method will close the 93// http.Response Body if it receives an error. 94func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) { 95 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 96} 97 98// ListResponder handles the response to the List request. The method always 99// closes the http.Response Body. 100func (client OperationsClient) ListResponder(resp *http.Response) (result OperationsDiscoveryCollection, err error) { 101 err = autorest.Respond( 102 resp, 103 azure.WithErrorUnlessStatusCode(http.StatusOK), 104 autorest.ByUnmarshallingJSON(&result), 105 autorest.ByClosing()) 106 result.Response = autorest.Response{Response: resp} 107 return 108} 109 110// listNextResults retrieves the next set of results, if any. 111func (client OperationsClient) listNextResults(ctx context.Context, lastResults OperationsDiscoveryCollection) (result OperationsDiscoveryCollection, err error) { 112 req, err := lastResults.operationsDiscoveryCollectionPreparer(ctx) 113 if err != nil { 114 return result, autorest.NewErrorWithError(err, "siterecovery.OperationsClient", "listNextResults", nil, "Failure preparing next results request") 115 } 116 if req == nil { 117 return 118 } 119 resp, err := client.ListSender(req) 120 if err != nil { 121 result.Response = autorest.Response{Response: resp} 122 return result, autorest.NewErrorWithError(err, "siterecovery.OperationsClient", "listNextResults", resp, "Failure sending next results request") 123 } 124 result, err = client.ListResponder(resp) 125 if err != nil { 126 err = autorest.NewErrorWithError(err, "siterecovery.OperationsClient", "listNextResults", resp, "Failure responding to next results request") 127 } 128 return 129} 130 131// ListComplete enumerates all values, automatically crossing page boundaries as required. 132func (client OperationsClient) ListComplete(ctx context.Context) (result OperationsDiscoveryCollectionIterator, err error) { 133 if tracing.IsEnabled() { 134 ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List") 135 defer func() { 136 sc := -1 137 if result.Response().Response.Response != nil { 138 sc = result.page.Response().Response.Response.StatusCode 139 } 140 tracing.EndSpan(ctx, sc, err) 141 }() 142 } 143 result.page, err = client.List(ctx) 144 return 145} 146