...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/postgresql/mgmt/2020-02-14-preview/postgresqlflexibleservers/checknameavailability.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/postgresql/mgmt/2020-02-14-preview/postgresqlflexibleservers

     1  package postgresqlflexibleservers
     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  // CheckNameAvailabilityClient is the the Microsoft Azure management API provides create, read, update, and delete
    19  // functionality for Azure PostgreSQL resources including servers, databases, firewall rules, VNET rules, security
    20  // alert policies, log files and configurations with new business model.
    21  type CheckNameAvailabilityClient struct {
    22  	BaseClient
    23  }
    24  
    25  // NewCheckNameAvailabilityClient creates an instance of the CheckNameAvailabilityClient client.
    26  func NewCheckNameAvailabilityClient(subscriptionID string) CheckNameAvailabilityClient {
    27  	return NewCheckNameAvailabilityClientWithBaseURI(DefaultBaseURI, subscriptionID)
    28  }
    29  
    30  // NewCheckNameAvailabilityClientWithBaseURI creates an instance of the CheckNameAvailabilityClient client using a
    31  // custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
    32  // Azure stack).
    33  func NewCheckNameAvailabilityClientWithBaseURI(baseURI string, subscriptionID string) CheckNameAvailabilityClient {
    34  	return CheckNameAvailabilityClient{NewWithBaseURI(baseURI, subscriptionID)}
    35  }
    36  
    37  // Execute check the availability of name for resource
    38  // Parameters:
    39  // nameAvailabilityRequest - the required parameters for checking if resource name is available.
    40  func (client CheckNameAvailabilityClient) Execute(ctx context.Context, nameAvailabilityRequest NameAvailabilityRequest) (result NameAvailability, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/CheckNameAvailabilityClient.Execute")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response.Response != nil {
    46  				sc = result.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}}},
    54  		{TargetValue: nameAvailabilityRequest,
    55  			Constraints: []validation.Constraint{{Target: "nameAvailabilityRequest.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    56  		return result, validation.NewError("postgresqlflexibleservers.CheckNameAvailabilityClient", "Execute", err.Error())
    57  	}
    58  
    59  	req, err := client.ExecutePreparer(ctx, nameAvailabilityRequest)
    60  	if err != nil {
    61  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.CheckNameAvailabilityClient", "Execute", nil, "Failure preparing request")
    62  		return
    63  	}
    64  
    65  	resp, err := client.ExecuteSender(req)
    66  	if err != nil {
    67  		result.Response = autorest.Response{Response: resp}
    68  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.CheckNameAvailabilityClient", "Execute", resp, "Failure sending request")
    69  		return
    70  	}
    71  
    72  	result, err = client.ExecuteResponder(resp)
    73  	if err != nil {
    74  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.CheckNameAvailabilityClient", "Execute", resp, "Failure responding to request")
    75  		return
    76  	}
    77  
    78  	return
    79  }
    80  
    81  // ExecutePreparer prepares the Execute request.
    82  func (client CheckNameAvailabilityClient) ExecutePreparer(ctx context.Context, nameAvailabilityRequest NameAvailabilityRequest) (*http.Request, error) {
    83  	pathParameters := map[string]interface{}{
    84  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    85  	}
    86  
    87  	const APIVersion = "2020-02-14-preview"
    88  	queryParameters := map[string]interface{}{
    89  		"api-version": APIVersion,
    90  	}
    91  
    92  	preparer := autorest.CreatePreparer(
    93  		autorest.AsContentType("application/json; charset=utf-8"),
    94  		autorest.AsPost(),
    95  		autorest.WithBaseURL(client.BaseURI),
    96  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DBForPostgreSql/checkNameAvailability", pathParameters),
    97  		autorest.WithJSON(nameAvailabilityRequest),
    98  		autorest.WithQueryParameters(queryParameters))
    99  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   100  }
   101  
   102  // ExecuteSender sends the Execute request. The method will close the
   103  // http.Response Body if it receives an error.
   104  func (client CheckNameAvailabilityClient) ExecuteSender(req *http.Request) (*http.Response, error) {
   105  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   106  }
   107  
   108  // ExecuteResponder handles the response to the Execute request. The method always
   109  // closes the http.Response Body.
   110  func (client CheckNameAvailabilityClient) ExecuteResponder(resp *http.Response) (result NameAvailability, err error) {
   111  	err = autorest.Respond(
   112  		resp,
   113  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   114  		autorest.ByUnmarshallingJSON(&result),
   115  		autorest.ByClosing())
   116  	result.Response = autorest.Response{Response: resp}
   117  	return
   118  }
   119  

View as plain text