1// Package network implements the Azure ARM Network service API version . 2// 3// Network Client 4package network 5 6// Copyright (c) Microsoft Corporation. All rights reserved. 7// Licensed under the MIT License. See License.txt in the project root for license information. 8// 9// Code generated by Microsoft (R) AutoRest Code Generator. 10// Changes may cause incorrect behavior and will be lost if the code is regenerated. 11 12import ( 13 "context" 14 "github.com/Azure/go-autorest/autorest" 15 "github.com/Azure/go-autorest/autorest/azure" 16 "github.com/Azure/go-autorest/tracing" 17 "net/http" 18) 19 20const ( 21 // DefaultBaseURI is the default URI used for the service Network 22 DefaultBaseURI = "https://management.azure.com" 23) 24 25// BaseClient is the base client for Network. 26type BaseClient struct { 27 autorest.Client 28 BaseURI string 29 SubscriptionID string 30} 31 32// New creates an instance of the BaseClient client. 33func New(subscriptionID string) BaseClient { 34 return NewWithBaseURI(DefaultBaseURI, subscriptionID) 35} 36 37// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint. Use this when interacting with 38// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 39func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { 40 return BaseClient{ 41 Client: autorest.NewClientWithUserAgent(UserAgent()), 42 BaseURI: baseURI, 43 SubscriptionID: subscriptionID, 44 } 45} 46 47// CheckDNSNameAvailability checks whether a domain name in the cloudapp.azure.com zone is available for use. 48// Parameters: 49// location - the location of the domain name. 50// domainNameLabel - the domain name to be verified. It must conform to the following regular expression: 51// ^[a-z][a-z0-9-]{1,61}[a-z0-9]$. 52func (client BaseClient) CheckDNSNameAvailability(ctx context.Context, location string, domainNameLabel string) (result DNSNameAvailabilityResult, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.CheckDNSNameAvailability") 55 defer func() { 56 sc := -1 57 if result.Response.Response != nil { 58 sc = result.Response.Response.StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 req, err := client.CheckDNSNameAvailabilityPreparer(ctx, location, domainNameLabel) 64 if err != nil { 65 err = autorest.NewErrorWithError(err, "network.BaseClient", "CheckDNSNameAvailability", nil, "Failure preparing request") 66 return 67 } 68 69 resp, err := client.CheckDNSNameAvailabilitySender(req) 70 if err != nil { 71 result.Response = autorest.Response{Response: resp} 72 err = autorest.NewErrorWithError(err, "network.BaseClient", "CheckDNSNameAvailability", resp, "Failure sending request") 73 return 74 } 75 76 result, err = client.CheckDNSNameAvailabilityResponder(resp) 77 if err != nil { 78 err = autorest.NewErrorWithError(err, "network.BaseClient", "CheckDNSNameAvailability", resp, "Failure responding to request") 79 return 80 } 81 82 return 83} 84 85// CheckDNSNameAvailabilityPreparer prepares the CheckDNSNameAvailability request. 86func (client BaseClient) CheckDNSNameAvailabilityPreparer(ctx context.Context, location string, domainNameLabel string) (*http.Request, error) { 87 pathParameters := map[string]interface{}{ 88 "location": autorest.Encode("path", location), 89 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 90 } 91 92 const APIVersion = "2017-10-01" 93 queryParameters := map[string]interface{}{ 94 "api-version": APIVersion, 95 "domainNameLabel": autorest.Encode("query", domainNameLabel), 96 } 97 98 preparer := autorest.CreatePreparer( 99 autorest.AsGet(), 100 autorest.WithBaseURL(client.BaseURI), 101 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/CheckDnsNameAvailability", pathParameters), 102 autorest.WithQueryParameters(queryParameters)) 103 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 104} 105 106// CheckDNSNameAvailabilitySender sends the CheckDNSNameAvailability request. The method will close the 107// http.Response Body if it receives an error. 108func (client BaseClient) CheckDNSNameAvailabilitySender(req *http.Request) (*http.Response, error) { 109 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 110} 111 112// CheckDNSNameAvailabilityResponder handles the response to the CheckDNSNameAvailability request. The method always 113// closes the http.Response Body. 114func (client BaseClient) CheckDNSNameAvailabilityResponder(resp *http.Response) (result DNSNameAvailabilityResult, 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