...

Source file src/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2021-07-01/features/client.go

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

     1  // Deprecated: Please note, this package has been deprecated. A replacement package is available [github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures). We strongly encourage you to upgrade to continue receiving updates. See [Migration Guide](https://aka.ms/azsdk/golang/t2/migration) for guidance on upgrading. Refer to our [deprecation policy](https://azure.github.io/azure-sdk/policies_support.html) for more details.
     2  //
     3  // Package features implements the Azure ARM Features service API version 2021-07-01.
     4  //
     5  //
     6  package features
     7  
     8  // Copyright (c) Microsoft Corporation. All rights reserved.
     9  // Licensed under the MIT License. See License.txt in the project root for license information.
    10  //
    11  // Code generated by Microsoft (R) AutoRest Code Generator.
    12  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
    13  
    14  import (
    15  	"context"
    16  	"github.com/Azure/go-autorest/autorest"
    17  	"github.com/Azure/go-autorest/autorest/azure"
    18  	"github.com/Azure/go-autorest/tracing"
    19  	"net/http"
    20  )
    21  
    22  const (
    23  	// DefaultBaseURI is the default URI used for the service Features
    24  	DefaultBaseURI = "https://management.azure.com"
    25  )
    26  
    27  // BaseClient is the base client for Features.
    28  type BaseClient struct {
    29  	autorest.Client
    30  	BaseURI        string
    31  	SubscriptionID string
    32  }
    33  
    34  // New creates an instance of the BaseClient client.
    35  func New(subscriptionID string) BaseClient {
    36  	return NewWithBaseURI(DefaultBaseURI, subscriptionID)
    37  }
    38  
    39  // NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint.  Use this when interacting with
    40  // an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    41  func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient {
    42  	return BaseClient{
    43  		Client:         autorest.NewClientWithUserAgent(UserAgent()),
    44  		BaseURI:        baseURI,
    45  		SubscriptionID: subscriptionID,
    46  	}
    47  }
    48  
    49  // ListOperations lists all of the available Microsoft.Features REST API operations.
    50  func (client BaseClient) ListOperations(ctx context.Context) (result OperationListResultPage, err error) {
    51  	if tracing.IsEnabled() {
    52  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.ListOperations")
    53  		defer func() {
    54  			sc := -1
    55  			if result.olr.Response.Response != nil {
    56  				sc = result.olr.Response.Response.StatusCode
    57  			}
    58  			tracing.EndSpan(ctx, sc, err)
    59  		}()
    60  	}
    61  	result.fn = client.listOperationsNextResults
    62  	req, err := client.ListOperationsPreparer(ctx)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "features.BaseClient", "ListOperations", nil, "Failure preparing request")
    65  		return
    66  	}
    67  
    68  	resp, err := client.ListOperationsSender(req)
    69  	if err != nil {
    70  		result.olr.Response = autorest.Response{Response: resp}
    71  		err = autorest.NewErrorWithError(err, "features.BaseClient", "ListOperations", resp, "Failure sending request")
    72  		return
    73  	}
    74  
    75  	result.olr, err = client.ListOperationsResponder(resp)
    76  	if err != nil {
    77  		err = autorest.NewErrorWithError(err, "features.BaseClient", "ListOperations", resp, "Failure responding to request")
    78  		return
    79  	}
    80  	if result.olr.hasNextLink() && result.olr.IsEmpty() {
    81  		err = result.NextWithContext(ctx)
    82  		return
    83  	}
    84  
    85  	return
    86  }
    87  
    88  // ListOperationsPreparer prepares the ListOperations request.
    89  func (client BaseClient) ListOperationsPreparer(ctx context.Context) (*http.Request, error) {
    90  	const APIVersion = "2021-07-01"
    91  	queryParameters := map[string]interface{}{
    92  		"api-version": APIVersion,
    93  	}
    94  
    95  	preparer := autorest.CreatePreparer(
    96  		autorest.AsGet(),
    97  		autorest.WithBaseURL(client.BaseURI),
    98  		autorest.WithPath("/providers/Microsoft.Features/operations"),
    99  		autorest.WithQueryParameters(queryParameters))
   100  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   101  }
   102  
   103  // ListOperationsSender sends the ListOperations request. The method will close the
   104  // http.Response Body if it receives an error.
   105  func (client BaseClient) ListOperationsSender(req *http.Request) (*http.Response, error) {
   106  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   107  }
   108  
   109  // ListOperationsResponder handles the response to the ListOperations request. The method always
   110  // closes the http.Response Body.
   111  func (client BaseClient) ListOperationsResponder(resp *http.Response) (result OperationListResult, err error) {
   112  	err = autorest.Respond(
   113  		resp,
   114  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   115  		autorest.ByUnmarshallingJSON(&result),
   116  		autorest.ByClosing())
   117  	result.Response = autorest.Response{Response: resp}
   118  	return
   119  }
   120  
   121  // listOperationsNextResults retrieves the next set of results, if any.
   122  func (client BaseClient) listOperationsNextResults(ctx context.Context, lastResults OperationListResult) (result OperationListResult, err error) {
   123  	req, err := lastResults.operationListResultPreparer(ctx)
   124  	if err != nil {
   125  		return result, autorest.NewErrorWithError(err, "features.BaseClient", "listOperationsNextResults", nil, "Failure preparing next results request")
   126  	}
   127  	if req == nil {
   128  		return
   129  	}
   130  	resp, err := client.ListOperationsSender(req)
   131  	if err != nil {
   132  		result.Response = autorest.Response{Response: resp}
   133  		return result, autorest.NewErrorWithError(err, "features.BaseClient", "listOperationsNextResults", resp, "Failure sending next results request")
   134  	}
   135  	result, err = client.ListOperationsResponder(resp)
   136  	if err != nil {
   137  		err = autorest.NewErrorWithError(err, "features.BaseClient", "listOperationsNextResults", resp, "Failure responding to next results request")
   138  	}
   139  	return
   140  }
   141  
   142  // ListOperationsComplete enumerates all values, automatically crossing page boundaries as required.
   143  func (client BaseClient) ListOperationsComplete(ctx context.Context) (result OperationListResultIterator, err error) {
   144  	if tracing.IsEnabled() {
   145  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.ListOperations")
   146  		defer func() {
   147  			sc := -1
   148  			if result.Response().Response.Response != nil {
   149  				sc = result.page.Response().Response.Response.StatusCode
   150  			}
   151  			tracing.EndSpan(ctx, sc, err)
   152  		}()
   153  	}
   154  	result.page, err = client.ListOperations(ctx)
   155  	return
   156  }
   157  

View as plain text