...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2019-05-13/backup/protectionintentgroup.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2019-05-13/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  // ProtectionIntentGroupClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type ProtectionIntentGroupClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewProtectionIntentGroupClient creates an instance of the ProtectionIntentGroupClient client.
    23  func NewProtectionIntentGroupClient(subscriptionID string) ProtectionIntentGroupClient {
    24  	return NewProtectionIntentGroupClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewProtectionIntentGroupClientWithBaseURI creates an instance of the ProtectionIntentGroupClient client using a
    28  // custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
    29  // Azure stack).
    30  func NewProtectionIntentGroupClientWithBaseURI(baseURI string, subscriptionID string) ProtectionIntentGroupClient {
    31  	return ProtectionIntentGroupClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // List provides a pageable list of all intents that are present within a vault.
    35  // Parameters:
    36  // vaultName - the name of the recovery services vault.
    37  // resourceGroupName - the name of the resource group where the recovery services vault is present.
    38  // filter - oData filter options.
    39  // skipToken - skipToken Filter.
    40  func (client ProtectionIntentGroupClient) List(ctx context.Context, vaultName string, resourceGroupName string, filter string, skipToken string) (result ProtectionIntentResourceListPage, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionIntentGroupClient.List")
    43  		defer func() {
    44  			sc := -1
    45  			if result.pirl.Response.Response != nil {
    46  				sc = result.pirl.Response.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	result.fn = client.listNextResults
    52  	req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, filter, skipToken)
    53  	if err != nil {
    54  		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentGroupClient", "List", nil, "Failure preparing request")
    55  		return
    56  	}
    57  
    58  	resp, err := client.ListSender(req)
    59  	if err != nil {
    60  		result.pirl.Response = autorest.Response{Response: resp}
    61  		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentGroupClient", "List", resp, "Failure sending request")
    62  		return
    63  	}
    64  
    65  	result.pirl, err = client.ListResponder(resp)
    66  	if err != nil {
    67  		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentGroupClient", "List", resp, "Failure responding to request")
    68  		return
    69  	}
    70  	if result.pirl.hasNextLink() && result.pirl.IsEmpty() {
    71  		err = result.NextWithContext(ctx)
    72  		return
    73  	}
    74  
    75  	return
    76  }
    77  
    78  // ListPreparer prepares the List request.
    79  func (client ProtectionIntentGroupClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, filter string, skipToken string) (*http.Request, error) {
    80  	pathParameters := map[string]interface{}{
    81  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    82  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    83  		"vaultName":         autorest.Encode("path", vaultName),
    84  	}
    85  
    86  	const APIVersion = "2017-07-01"
    87  	queryParameters := map[string]interface{}{
    88  		"api-version": APIVersion,
    89  	}
    90  	if len(filter) > 0 {
    91  		queryParameters["$filter"] = autorest.Encode("query", filter)
    92  	}
    93  	if len(skipToken) > 0 {
    94  		queryParameters["$skipToken"] = autorest.Encode("query", skipToken)
    95  	}
    96  
    97  	preparer := autorest.CreatePreparer(
    98  		autorest.AsGet(),
    99  		autorest.WithBaseURL(client.BaseURI),
   100  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupProtectionIntents", pathParameters),
   101  		autorest.WithQueryParameters(queryParameters))
   102  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   103  }
   104  
   105  // ListSender sends the List request. The method will close the
   106  // http.Response Body if it receives an error.
   107  func (client ProtectionIntentGroupClient) ListSender(req *http.Request) (*http.Response, error) {
   108  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   109  }
   110  
   111  // ListResponder handles the response to the List request. The method always
   112  // closes the http.Response Body.
   113  func (client ProtectionIntentGroupClient) ListResponder(resp *http.Response) (result ProtectionIntentResourceList, err error) {
   114  	err = autorest.Respond(
   115  		resp,
   116  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   117  		autorest.ByUnmarshallingJSON(&result),
   118  		autorest.ByClosing())
   119  	result.Response = autorest.Response{Response: resp}
   120  	return
   121  }
   122  
   123  // listNextResults retrieves the next set of results, if any.
   124  func (client ProtectionIntentGroupClient) listNextResults(ctx context.Context, lastResults ProtectionIntentResourceList) (result ProtectionIntentResourceList, err error) {
   125  	req, err := lastResults.protectionIntentResourceListPreparer(ctx)
   126  	if err != nil {
   127  		return result, autorest.NewErrorWithError(err, "backup.ProtectionIntentGroupClient", "listNextResults", nil, "Failure preparing next results request")
   128  	}
   129  	if req == nil {
   130  		return
   131  	}
   132  	resp, err := client.ListSender(req)
   133  	if err != nil {
   134  		result.Response = autorest.Response{Response: resp}
   135  		return result, autorest.NewErrorWithError(err, "backup.ProtectionIntentGroupClient", "listNextResults", resp, "Failure sending next results request")
   136  	}
   137  	result, err = client.ListResponder(resp)
   138  	if err != nil {
   139  		err = autorest.NewErrorWithError(err, "backup.ProtectionIntentGroupClient", "listNextResults", resp, "Failure responding to next results request")
   140  	}
   141  	return
   142  }
   143  
   144  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   145  func (client ProtectionIntentGroupClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string, filter string, skipToken string) (result ProtectionIntentResourceListIterator, err error) {
   146  	if tracing.IsEnabled() {
   147  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionIntentGroupClient.List")
   148  		defer func() {
   149  			sc := -1
   150  			if result.Response().Response.Response != nil {
   151  				sc = result.page.Response().Response.Response.StatusCode
   152  			}
   153  			tracing.EndSpan(ctx, sc, err)
   154  		}()
   155  	}
   156  	result.page, err = client.List(ctx, vaultName, resourceGroupName, filter, skipToken)
   157  	return
   158  }
   159  

View as plain text