1// Package frontdoor implements the Azure ARM Frontdoor service API version . 2// 3// FrontDoor Client 4package frontdoor 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/autorest/validation" 17 "github.com/Azure/go-autorest/tracing" 18 "net/http" 19) 20 21const ( 22 // DefaultBaseURI is the default URI used for the service Frontdoor 23 DefaultBaseURI = "https://management.azure.com" 24) 25 26// BaseClient is the base client for Frontdoor. 27type BaseClient struct { 28 autorest.Client 29 BaseURI string 30 SubscriptionID string 31} 32 33// New creates an instance of the BaseClient client. 34func New(subscriptionID string) BaseClient { 35 return NewWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint. Use this when interacting with 39// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 40func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { 41 return BaseClient{ 42 Client: autorest.NewClientWithUserAgent(UserAgent()), 43 BaseURI: baseURI, 44 SubscriptionID: subscriptionID, 45 } 46} 47 48// CheckFrontDoorNameAvailability check the availability of a Front Door resource name. 49// Parameters: 50// checkFrontDoorNameAvailabilityInput - input to check. 51func (client BaseClient) CheckFrontDoorNameAvailability(ctx context.Context, checkFrontDoorNameAvailabilityInput CheckNameAvailabilityInput) (result CheckNameAvailabilityOutput, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.CheckFrontDoorNameAvailability") 54 defer func() { 55 sc := -1 56 if result.Response.Response != nil { 57 sc = result.Response.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 if err := validation.Validate([]validation.Validation{ 63 {TargetValue: checkFrontDoorNameAvailabilityInput, 64 Constraints: []validation.Constraint{{Target: "checkFrontDoorNameAvailabilityInput.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 65 return result, validation.NewError("frontdoor.BaseClient", "CheckFrontDoorNameAvailability", err.Error()) 66 } 67 68 req, err := client.CheckFrontDoorNameAvailabilityPreparer(ctx, checkFrontDoorNameAvailabilityInput) 69 if err != nil { 70 err = autorest.NewErrorWithError(err, "frontdoor.BaseClient", "CheckFrontDoorNameAvailability", nil, "Failure preparing request") 71 return 72 } 73 74 resp, err := client.CheckFrontDoorNameAvailabilitySender(req) 75 if err != nil { 76 result.Response = autorest.Response{Response: resp} 77 err = autorest.NewErrorWithError(err, "frontdoor.BaseClient", "CheckFrontDoorNameAvailability", resp, "Failure sending request") 78 return 79 } 80 81 result, err = client.CheckFrontDoorNameAvailabilityResponder(resp) 82 if err != nil { 83 err = autorest.NewErrorWithError(err, "frontdoor.BaseClient", "CheckFrontDoorNameAvailability", resp, "Failure responding to request") 84 return 85 } 86 87 return 88} 89 90// CheckFrontDoorNameAvailabilityPreparer prepares the CheckFrontDoorNameAvailability request. 91func (client BaseClient) CheckFrontDoorNameAvailabilityPreparer(ctx context.Context, checkFrontDoorNameAvailabilityInput CheckNameAvailabilityInput) (*http.Request, error) { 92 const APIVersion = "2019-05-01" 93 queryParameters := map[string]interface{}{ 94 "api-version": APIVersion, 95 } 96 97 preparer := autorest.CreatePreparer( 98 autorest.AsContentType("application/json; charset=utf-8"), 99 autorest.AsPost(), 100 autorest.WithBaseURL(client.BaseURI), 101 autorest.WithPath("/providers/Microsoft.Network/checkFrontDoorNameAvailability"), 102 autorest.WithJSON(checkFrontDoorNameAvailabilityInput), 103 autorest.WithQueryParameters(queryParameters)) 104 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 105} 106 107// CheckFrontDoorNameAvailabilitySender sends the CheckFrontDoorNameAvailability request. The method will close the 108// http.Response Body if it receives an error. 109func (client BaseClient) CheckFrontDoorNameAvailabilitySender(req *http.Request) (*http.Response, error) { 110 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 111} 112 113// CheckFrontDoorNameAvailabilityResponder handles the response to the CheckFrontDoorNameAvailability request. The method always 114// closes the http.Response Body. 115func (client BaseClient) CheckFrontDoorNameAvailabilityResponder(resp *http.Response) (result CheckNameAvailabilityOutput, err error) { 116 err = autorest.Respond( 117 resp, 118 azure.WithErrorUnlessStatusCode(http.StatusOK), 119 autorest.ByUnmarshallingJSON(&result), 120 autorest.ByClosing()) 121 result.Response = autorest.Response{Response: resp} 122 return 123} 124 125// CheckFrontDoorNameAvailabilityWithSubscription check the availability of a Front Door subdomain. 126// Parameters: 127// checkFrontDoorNameAvailabilityInput - input to check. 128func (client BaseClient) CheckFrontDoorNameAvailabilityWithSubscription(ctx context.Context, checkFrontDoorNameAvailabilityInput CheckNameAvailabilityInput) (result CheckNameAvailabilityOutput, err error) { 129 if tracing.IsEnabled() { 130 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.CheckFrontDoorNameAvailabilityWithSubscription") 131 defer func() { 132 sc := -1 133 if result.Response.Response != nil { 134 sc = result.Response.Response.StatusCode 135 } 136 tracing.EndSpan(ctx, sc, err) 137 }() 138 } 139 if err := validation.Validate([]validation.Validation{ 140 {TargetValue: checkFrontDoorNameAvailabilityInput, 141 Constraints: []validation.Constraint{{Target: "checkFrontDoorNameAvailabilityInput.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 142 return result, validation.NewError("frontdoor.BaseClient", "CheckFrontDoorNameAvailabilityWithSubscription", err.Error()) 143 } 144 145 req, err := client.CheckFrontDoorNameAvailabilityWithSubscriptionPreparer(ctx, checkFrontDoorNameAvailabilityInput) 146 if err != nil { 147 err = autorest.NewErrorWithError(err, "frontdoor.BaseClient", "CheckFrontDoorNameAvailabilityWithSubscription", nil, "Failure preparing request") 148 return 149 } 150 151 resp, err := client.CheckFrontDoorNameAvailabilityWithSubscriptionSender(req) 152 if err != nil { 153 result.Response = autorest.Response{Response: resp} 154 err = autorest.NewErrorWithError(err, "frontdoor.BaseClient", "CheckFrontDoorNameAvailabilityWithSubscription", resp, "Failure sending request") 155 return 156 } 157 158 result, err = client.CheckFrontDoorNameAvailabilityWithSubscriptionResponder(resp) 159 if err != nil { 160 err = autorest.NewErrorWithError(err, "frontdoor.BaseClient", "CheckFrontDoorNameAvailabilityWithSubscription", resp, "Failure responding to request") 161 return 162 } 163 164 return 165} 166 167// CheckFrontDoorNameAvailabilityWithSubscriptionPreparer prepares the CheckFrontDoorNameAvailabilityWithSubscription request. 168func (client BaseClient) CheckFrontDoorNameAvailabilityWithSubscriptionPreparer(ctx context.Context, checkFrontDoorNameAvailabilityInput CheckNameAvailabilityInput) (*http.Request, error) { 169 pathParameters := map[string]interface{}{ 170 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 171 } 172 173 const APIVersion = "2019-05-01" 174 queryParameters := map[string]interface{}{ 175 "api-version": APIVersion, 176 } 177 178 preparer := autorest.CreatePreparer( 179 autorest.AsContentType("application/json; charset=utf-8"), 180 autorest.AsPost(), 181 autorest.WithBaseURL(client.BaseURI), 182 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/checkFrontDoorNameAvailability", pathParameters), 183 autorest.WithJSON(checkFrontDoorNameAvailabilityInput), 184 autorest.WithQueryParameters(queryParameters)) 185 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 186} 187 188// CheckFrontDoorNameAvailabilityWithSubscriptionSender sends the CheckFrontDoorNameAvailabilityWithSubscription request. The method will close the 189// http.Response Body if it receives an error. 190func (client BaseClient) CheckFrontDoorNameAvailabilityWithSubscriptionSender(req *http.Request) (*http.Response, error) { 191 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 192} 193 194// CheckFrontDoorNameAvailabilityWithSubscriptionResponder handles the response to the CheckFrontDoorNameAvailabilityWithSubscription request. The method always 195// closes the http.Response Body. 196func (client BaseClient) CheckFrontDoorNameAvailabilityWithSubscriptionResponder(resp *http.Response) (result CheckNameAvailabilityOutput, err error) { 197 err = autorest.Respond( 198 resp, 199 azure.WithErrorUnlessStatusCode(http.StatusOK), 200 autorest.ByUnmarshallingJSON(&result), 201 autorest.ByClosing()) 202 result.Response = autorest.Response{Response: resp} 203 return 204} 205