1package mysql 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "net/http" 26) 27 28// CheckNameAvailabilityClient is the the Microsoft Azure management API provides create, read, update, and delete 29// functionality for Azure MySQL resources including servers, databases, firewall rules, VNET rules, log files and 30// configurations with new business model. 31type CheckNameAvailabilityClient struct { 32 BaseClient 33} 34 35// NewCheckNameAvailabilityClient creates an instance of the CheckNameAvailabilityClient client. 36func NewCheckNameAvailabilityClient(subscriptionID string) CheckNameAvailabilityClient { 37 return NewCheckNameAvailabilityClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewCheckNameAvailabilityClientWithBaseURI creates an instance of the CheckNameAvailabilityClient client. 41func NewCheckNameAvailabilityClientWithBaseURI(baseURI string, subscriptionID string) CheckNameAvailabilityClient { 42 return CheckNameAvailabilityClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// Execute check the availability of name for resource 46// Parameters: 47// nameAvailabilityRequest - the required parameters for checking if resource name is available. 48func (client CheckNameAvailabilityClient) Execute(ctx context.Context, nameAvailabilityRequest NameAvailabilityRequest) (result NameAvailability, err error) { 49 if err := validation.Validate([]validation.Validation{ 50 {TargetValue: nameAvailabilityRequest, 51 Constraints: []validation.Constraint{{Target: "nameAvailabilityRequest.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 52 return result, validation.NewError("mysql.CheckNameAvailabilityClient", "Execute", err.Error()) 53 } 54 55 req, err := client.ExecutePreparer(ctx, nameAvailabilityRequest) 56 if err != nil { 57 err = autorest.NewErrorWithError(err, "mysql.CheckNameAvailabilityClient", "Execute", nil, "Failure preparing request") 58 return 59 } 60 61 resp, err := client.ExecuteSender(req) 62 if err != nil { 63 result.Response = autorest.Response{Response: resp} 64 err = autorest.NewErrorWithError(err, "mysql.CheckNameAvailabilityClient", "Execute", resp, "Failure sending request") 65 return 66 } 67 68 result, err = client.ExecuteResponder(resp) 69 if err != nil { 70 err = autorest.NewErrorWithError(err, "mysql.CheckNameAvailabilityClient", "Execute", resp, "Failure responding to request") 71 } 72 73 return 74} 75 76// ExecutePreparer prepares the Execute request. 77func (client CheckNameAvailabilityClient) ExecutePreparer(ctx context.Context, nameAvailabilityRequest NameAvailabilityRequest) (*http.Request, error) { 78 pathParameters := map[string]interface{}{ 79 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 80 } 81 82 const APIVersion = "2017-12-01" 83 queryParameters := map[string]interface{}{ 84 "api-version": APIVersion, 85 } 86 87 preparer := autorest.CreatePreparer( 88 autorest.AsContentType("application/json; charset=utf-8"), 89 autorest.AsPost(), 90 autorest.WithBaseURL(client.BaseURI), 91 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DBforMySQL/checkNameAvailability", pathParameters), 92 autorest.WithJSON(nameAvailabilityRequest), 93 autorest.WithQueryParameters(queryParameters)) 94 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 95} 96 97// ExecuteSender sends the Execute request. The method will close the 98// http.Response Body if it receives an error. 99func (client CheckNameAvailabilityClient) ExecuteSender(req *http.Request) (*http.Response, error) { 100 return autorest.SendWithSender(client, req, 101 azure.DoRetryWithRegistration(client.Client)) 102} 103 104// ExecuteResponder handles the response to the Execute request. The method always 105// closes the http.Response Body. 106func (client CheckNameAvailabilityClient) ExecuteResponder(resp *http.Response) (result NameAvailability, err error) { 107 err = autorest.Respond( 108 resp, 109 client.ByInspecting(), 110 azure.WithErrorUnlessStatusCode(http.StatusOK), 111 autorest.ByUnmarshallingJSON(&result), 112 autorest.ByClosing()) 113 result.Response = autorest.Response{Response: resp} 114 return 115} 116