...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/mysql/mgmt/2021-05-01-preview/mysqlflexibleservers/locationbasedcapabilities.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/mysql/mgmt/2021-05-01-preview/mysqlflexibleservers

     1  package mysqlflexibleservers
     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/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // LocationBasedCapabilitiesClient is the the Microsoft Azure management API provides create, read, update, and delete
    19  // functionality for Azure MySQL resources including servers, databases, firewall rules, VNET rules, log files and
    20  // configurations with new business model.
    21  type LocationBasedCapabilitiesClient struct {
    22  	BaseClient
    23  }
    24  
    25  // NewLocationBasedCapabilitiesClient creates an instance of the LocationBasedCapabilitiesClient client.
    26  func NewLocationBasedCapabilitiesClient(subscriptionID string) LocationBasedCapabilitiesClient {
    27  	return NewLocationBasedCapabilitiesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    28  }
    29  
    30  // NewLocationBasedCapabilitiesClientWithBaseURI creates an instance of the LocationBasedCapabilitiesClient client
    31  // using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
    32  // clouds, Azure stack).
    33  func NewLocationBasedCapabilitiesClientWithBaseURI(baseURI string, subscriptionID string) LocationBasedCapabilitiesClient {
    34  	return LocationBasedCapabilitiesClient{NewWithBaseURI(baseURI, subscriptionID)}
    35  }
    36  
    37  // List get capabilities at specified location in a given subscription.
    38  // Parameters:
    39  // locationName - the name of the location.
    40  func (client LocationBasedCapabilitiesClient) List(ctx context.Context, locationName string) (result CapabilitiesListResultPage, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/LocationBasedCapabilitiesClient.List")
    43  		defer func() {
    44  			sc := -1
    45  			if result.clr.Response.Response != nil {
    46  				sc = result.clr.Response.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	if err := validation.Validate([]validation.Validation{
    52  		{TargetValue: client.SubscriptionID,
    53  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    54  		return result, validation.NewError("mysqlflexibleservers.LocationBasedCapabilitiesClient", "List", err.Error())
    55  	}
    56  
    57  	result.fn = client.listNextResults
    58  	req, err := client.ListPreparer(ctx, locationName)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.LocationBasedCapabilitiesClient", "List", nil, "Failure preparing request")
    61  		return
    62  	}
    63  
    64  	resp, err := client.ListSender(req)
    65  	if err != nil {
    66  		result.clr.Response = autorest.Response{Response: resp}
    67  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.LocationBasedCapabilitiesClient", "List", resp, "Failure sending request")
    68  		return
    69  	}
    70  
    71  	result.clr, err = client.ListResponder(resp)
    72  	if err != nil {
    73  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.LocationBasedCapabilitiesClient", "List", resp, "Failure responding to request")
    74  		return
    75  	}
    76  	if result.clr.hasNextLink() && result.clr.IsEmpty() {
    77  		err = result.NextWithContext(ctx)
    78  		return
    79  	}
    80  
    81  	return
    82  }
    83  
    84  // ListPreparer prepares the List request.
    85  func (client LocationBasedCapabilitiesClient) ListPreparer(ctx context.Context, locationName string) (*http.Request, error) {
    86  	pathParameters := map[string]interface{}{
    87  		"locationName":   autorest.Encode("path", locationName),
    88  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    89  	}
    90  
    91  	const APIVersion = "2021-05-01-preview"
    92  	queryParameters := map[string]interface{}{
    93  		"api-version": APIVersion,
    94  	}
    95  
    96  	preparer := autorest.CreatePreparer(
    97  		autorest.AsGet(),
    98  		autorest.WithBaseURL(client.BaseURI),
    99  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DBforMySQL/locations/{locationName}/capabilities", pathParameters),
   100  		autorest.WithQueryParameters(queryParameters))
   101  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   102  }
   103  
   104  // ListSender sends the List request. The method will close the
   105  // http.Response Body if it receives an error.
   106  func (client LocationBasedCapabilitiesClient) ListSender(req *http.Request) (*http.Response, error) {
   107  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   108  }
   109  
   110  // ListResponder handles the response to the List request. The method always
   111  // closes the http.Response Body.
   112  func (client LocationBasedCapabilitiesClient) ListResponder(resp *http.Response) (result CapabilitiesListResult, err error) {
   113  	err = autorest.Respond(
   114  		resp,
   115  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   116  		autorest.ByUnmarshallingJSON(&result),
   117  		autorest.ByClosing())
   118  	result.Response = autorest.Response{Response: resp}
   119  	return
   120  }
   121  
   122  // listNextResults retrieves the next set of results, if any.
   123  func (client LocationBasedCapabilitiesClient) listNextResults(ctx context.Context, lastResults CapabilitiesListResult) (result CapabilitiesListResult, err error) {
   124  	req, err := lastResults.capabilitiesListResultPreparer(ctx)
   125  	if err != nil {
   126  		return result, autorest.NewErrorWithError(err, "mysqlflexibleservers.LocationBasedCapabilitiesClient", "listNextResults", nil, "Failure preparing next results request")
   127  	}
   128  	if req == nil {
   129  		return
   130  	}
   131  	resp, err := client.ListSender(req)
   132  	if err != nil {
   133  		result.Response = autorest.Response{Response: resp}
   134  		return result, autorest.NewErrorWithError(err, "mysqlflexibleservers.LocationBasedCapabilitiesClient", "listNextResults", resp, "Failure sending next results request")
   135  	}
   136  	result, err = client.ListResponder(resp)
   137  	if err != nil {
   138  		err = autorest.NewErrorWithError(err, "mysqlflexibleservers.LocationBasedCapabilitiesClient", "listNextResults", resp, "Failure responding to next results request")
   139  	}
   140  	return
   141  }
   142  
   143  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   144  func (client LocationBasedCapabilitiesClient) ListComplete(ctx context.Context, locationName string) (result CapabilitiesListResultIterator, err error) {
   145  	if tracing.IsEnabled() {
   146  		ctx = tracing.StartSpan(ctx, fqdn+"/LocationBasedCapabilitiesClient.List")
   147  		defer func() {
   148  			sc := -1
   149  			if result.Response().Response.Response != nil {
   150  				sc = result.page.Response().Response.Response.StatusCode
   151  			}
   152  			tracing.EndSpan(ctx, sc, err)
   153  		}()
   154  	}
   155  	result.page, err = client.List(ctx, locationName)
   156  	return
   157  }
   158  

View as plain text