1// Package engagementfabric implements the Azure ARM Engagementfabric service API version 2018-09-01-preview. 2// 3// Microsoft Customer Engagement Fabric 4package engagementfabric 5 6// Copyright (c) Microsoft and contributors. All rights reserved. 7// 8// Licensed under the Apache License, Version 2.0 (the "License"); 9// you may not use this file except in compliance with the License. 10// You may obtain a copy of the License at 11// http://www.apache.org/licenses/LICENSE-2.0 12// 13// Unless required by applicable law or agreed to in writing, software 14// distributed under the License is distributed on an "AS IS" BASIS, 15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16// 17// See the License for the specific language governing permissions and 18// limitations under the License. 19// 20// Code generated by Microsoft (R) AutoRest Code Generator. 21// Changes may cause incorrect behavior and will be lost if the code is regenerated. 22 23import ( 24 "context" 25 "github.com/Azure/go-autorest/autorest" 26 "github.com/Azure/go-autorest/autorest/azure" 27 "github.com/Azure/go-autorest/autorest/validation" 28 "github.com/Azure/go-autorest/tracing" 29 "net/http" 30) 31 32const ( 33 // DefaultBaseURI is the default URI used for the service Engagementfabric 34 DefaultBaseURI = "https://management.azure.com" 35) 36 37// BaseClient is the base client for Engagementfabric. 38type BaseClient struct { 39 autorest.Client 40 BaseURI string 41 SubscriptionID string 42} 43 44// New creates an instance of the BaseClient client. 45func New(subscriptionID string) BaseClient { 46 return NewWithBaseURI(DefaultBaseURI, subscriptionID) 47} 48 49// NewWithBaseURI creates an instance of the BaseClient client. 50func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { 51 return BaseClient{ 52 Client: autorest.NewClientWithUserAgent(UserAgent()), 53 BaseURI: baseURI, 54 SubscriptionID: subscriptionID, 55 } 56} 57 58// CheckNameAvailability sends the check name availability request. 59// Parameters: 60// resourceGroupName - resource Group Name 61// parameters - parameter describing the name to be checked 62func (client BaseClient) CheckNameAvailability(ctx context.Context, resourceGroupName string, parameters CheckNameAvailabilityParameter) (result CheckNameAvailabilityResult, err error) { 63 if tracing.IsEnabled() { 64 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.CheckNameAvailability") 65 defer func() { 66 sc := -1 67 if result.Response.Response != nil { 68 sc = result.Response.Response.StatusCode 69 } 70 tracing.EndSpan(ctx, sc, err) 71 }() 72 } 73 if err := validation.Validate([]validation.Validation{ 74 {TargetValue: parameters, 75 Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil}, 76 {Target: "parameters.Type", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 77 return result, validation.NewError("engagementfabric.BaseClient", "CheckNameAvailability", err.Error()) 78 } 79 80 req, err := client.CheckNameAvailabilityPreparer(ctx, resourceGroupName, parameters) 81 if err != nil { 82 err = autorest.NewErrorWithError(err, "engagementfabric.BaseClient", "CheckNameAvailability", nil, "Failure preparing request") 83 return 84 } 85 86 resp, err := client.CheckNameAvailabilitySender(req) 87 if err != nil { 88 result.Response = autorest.Response{Response: resp} 89 err = autorest.NewErrorWithError(err, "engagementfabric.BaseClient", "CheckNameAvailability", resp, "Failure sending request") 90 return 91 } 92 93 result, err = client.CheckNameAvailabilityResponder(resp) 94 if err != nil { 95 err = autorest.NewErrorWithError(err, "engagementfabric.BaseClient", "CheckNameAvailability", resp, "Failure responding to request") 96 } 97 98 return 99} 100 101// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request. 102func (client BaseClient) CheckNameAvailabilityPreparer(ctx context.Context, resourceGroupName string, parameters CheckNameAvailabilityParameter) (*http.Request, error) { 103 pathParameters := map[string]interface{}{ 104 "resourceGroupName": autorest.Encode("path", resourceGroupName), 105 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 106 } 107 108 const APIVersion = "2018-09-01-preview" 109 queryParameters := map[string]interface{}{ 110 "api-version": APIVersion, 111 } 112 113 preparer := autorest.CreatePreparer( 114 autorest.AsContentType("application/json; charset=utf-8"), 115 autorest.AsPost(), 116 autorest.WithBaseURL(client.BaseURI), 117 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EngagementFabric/checkNameAvailability", pathParameters), 118 autorest.WithJSON(parameters), 119 autorest.WithQueryParameters(queryParameters)) 120 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 121} 122 123// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the 124// http.Response Body if it receives an error. 125func (client BaseClient) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) { 126 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 127 return autorest.SendWithSender(client, req, sd...) 128} 129 130// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always 131// closes the http.Response Body. 132func (client BaseClient) CheckNameAvailabilityResponder(resp *http.Response) (result CheckNameAvailabilityResult, err error) { 133 err = autorest.Respond( 134 resp, 135 client.ByInspecting(), 136 azure.WithErrorUnlessStatusCode(http.StatusOK), 137 autorest.ByUnmarshallingJSON(&result), 138 autorest.ByClosing()) 139 result.Response = autorest.Response{Response: resp} 140 return 141} 142