...

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

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

View as plain text