...

Source file src/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-06-01/subscriptions/operations.go

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-06-01/subscriptions

     1  package subscriptions
     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 all resource groups and resources exist within subscriptions. These operation enable you get
    18  // information about your subscriptions and tenants. A tenant is a dedicated instance of Azure Active Directory (Azure
    19  // AD) for your organization.
    20  type OperationsClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewOperationsClient creates an instance of the OperationsClient client.
    25  func NewOperationsClient() OperationsClient {
    26  	return NewOperationsClientWithBaseURI(DefaultBaseURI)
    27  }
    28  
    29  // NewOperationsClientWithBaseURI creates an instance of the OperationsClient client using a custom endpoint.  Use this
    30  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    31  func NewOperationsClientWithBaseURI(baseURI string) OperationsClient {
    32  	return OperationsClient{NewWithBaseURI(baseURI)}
    33  }
    34  
    35  // List lists all of the available Microsoft.Resources REST API operations.
    36  func (client OperationsClient) List(ctx context.Context) (result OperationListResultPage, err error) {
    37  	if tracing.IsEnabled() {
    38  		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
    39  		defer func() {
    40  			sc := -1
    41  			if result.olr.Response.Response != nil {
    42  				sc = result.olr.Response.Response.StatusCode
    43  			}
    44  			tracing.EndSpan(ctx, sc, err)
    45  		}()
    46  	}
    47  	result.fn = client.listNextResults
    48  	req, err := client.ListPreparer(ctx)
    49  	if err != nil {
    50  		err = autorest.NewErrorWithError(err, "subscriptions.OperationsClient", "List", nil, "Failure preparing request")
    51  		return
    52  	}
    53  
    54  	resp, err := client.ListSender(req)
    55  	if err != nil {
    56  		result.olr.Response = autorest.Response{Response: resp}
    57  		err = autorest.NewErrorWithError(err, "subscriptions.OperationsClient", "List", resp, "Failure sending request")
    58  		return
    59  	}
    60  
    61  	result.olr, err = client.ListResponder(resp)
    62  	if err != nil {
    63  		err = autorest.NewErrorWithError(err, "subscriptions.OperationsClient", "List", resp, "Failure responding to request")
    64  		return
    65  	}
    66  	if result.olr.hasNextLink() && result.olr.IsEmpty() {
    67  		err = result.NextWithContext(ctx)
    68  		return
    69  	}
    70  
    71  	return
    72  }
    73  
    74  // ListPreparer prepares the List request.
    75  func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
    76  	const APIVersion = "2018-06-01"
    77  	queryParameters := map[string]interface{}{
    78  		"api-version": APIVersion,
    79  	}
    80  
    81  	preparer := autorest.CreatePreparer(
    82  		autorest.AsGet(),
    83  		autorest.WithBaseURL(client.BaseURI),
    84  		autorest.WithPath("/providers/Microsoft.Resources/operations"),
    85  		autorest.WithQueryParameters(queryParameters))
    86  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    87  }
    88  
    89  // ListSender sends the List request. The method will close the
    90  // http.Response Body if it receives an error.
    91  func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) {
    92  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    93  }
    94  
    95  // ListResponder handles the response to the List request. The method always
    96  // closes the http.Response Body.
    97  func (client OperationsClient) ListResponder(resp *http.Response) (result OperationListResult, err error) {
    98  	err = autorest.Respond(
    99  		resp,
   100  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   101  		autorest.ByUnmarshallingJSON(&result),
   102  		autorest.ByClosing())
   103  	result.Response = autorest.Response{Response: resp}
   104  	return
   105  }
   106  
   107  // listNextResults retrieves the next set of results, if any.
   108  func (client OperationsClient) listNextResults(ctx context.Context, lastResults OperationListResult) (result OperationListResult, err error) {
   109  	req, err := lastResults.operationListResultPreparer(ctx)
   110  	if err != nil {
   111  		return result, autorest.NewErrorWithError(err, "subscriptions.OperationsClient", "listNextResults", nil, "Failure preparing next results request")
   112  	}
   113  	if req == nil {
   114  		return
   115  	}
   116  	resp, err := client.ListSender(req)
   117  	if err != nil {
   118  		result.Response = autorest.Response{Response: resp}
   119  		return result, autorest.NewErrorWithError(err, "subscriptions.OperationsClient", "listNextResults", resp, "Failure sending next results request")
   120  	}
   121  	result, err = client.ListResponder(resp)
   122  	if err != nil {
   123  		err = autorest.NewErrorWithError(err, "subscriptions.OperationsClient", "listNextResults", resp, "Failure responding to next results request")
   124  	}
   125  	return
   126  }
   127  
   128  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   129  func (client OperationsClient) ListComplete(ctx context.Context) (result OperationListResultIterator, err error) {
   130  	if tracing.IsEnabled() {
   131  		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
   132  		defer func() {
   133  			sc := -1
   134  			if result.Response().Response.Response != nil {
   135  				sc = result.page.Response().Response.Response.StatusCode
   136  			}
   137  			tracing.EndSpan(ctx, sc, err)
   138  		}()
   139  	}
   140  	result.page, err = client.List(ctx)
   141  	return
   142  }
   143  

View as plain text