1package trafficmanager 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 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/tracing" 14 "net/http" 15) 16 17// EndpointsClient is the client for the Endpoints methods of the Trafficmanager service. 18type EndpointsClient struct { 19 BaseClient 20} 21 22// NewEndpointsClient creates an instance of the EndpointsClient client. 23func NewEndpointsClient(subscriptionID string) EndpointsClient { 24 return NewEndpointsClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewEndpointsClientWithBaseURI creates an instance of the EndpointsClient client using a custom endpoint. Use this 28// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewEndpointsClientWithBaseURI(baseURI string, subscriptionID string) EndpointsClient { 30 return EndpointsClient{NewWithBaseURI(baseURI, subscriptionID)} 31} 32 33// CreateOrUpdate create or update a Traffic Manager endpoint. 34// Parameters: 35// resourceGroupName - the name of the resource group containing the Traffic Manager endpoint to be created or 36// updated. 37// profileName - the name of the Traffic Manager profile. 38// endpointType - the type of the Traffic Manager endpoint to be created or updated. 39// endpointName - the name of the Traffic Manager endpoint to be created or updated. 40// parameters - the Traffic Manager endpoint parameters supplied to the CreateOrUpdate operation. 41func (client EndpointsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string, parameters Endpoint) (result Endpoint, err error) { 42 if tracing.IsEnabled() { 43 ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.CreateOrUpdate") 44 defer func() { 45 sc := -1 46 if result.Response.Response != nil { 47 sc = result.Response.Response.StatusCode 48 } 49 tracing.EndSpan(ctx, sc, err) 50 }() 51 } 52 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, profileName, endpointType, endpointName, parameters) 53 if err != nil { 54 err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "CreateOrUpdate", nil, "Failure preparing request") 55 return 56 } 57 58 resp, err := client.CreateOrUpdateSender(req) 59 if err != nil { 60 result.Response = autorest.Response{Response: resp} 61 err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "CreateOrUpdate", resp, "Failure sending request") 62 return 63 } 64 65 result, err = client.CreateOrUpdateResponder(resp) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "CreateOrUpdate", resp, "Failure responding to request") 68 return 69 } 70 71 return 72} 73 74// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 75func (client EndpointsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string, parameters Endpoint) (*http.Request, error) { 76 pathParameters := map[string]interface{}{ 77 "endpointName": autorest.Encode("path", endpointName), 78 "endpointType": autorest.Encode("path", endpointType), 79 "profileName": autorest.Encode("path", profileName), 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 82 } 83 84 const APIVersion = "2015-11-01" 85 queryParameters := map[string]interface{}{ 86 "api-version": APIVersion, 87 } 88 89 preparer := autorest.CreatePreparer( 90 autorest.AsContentType("application/json; charset=utf-8"), 91 autorest.AsPut(), 92 autorest.WithBaseURL(client.BaseURI), 93 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}/{endpointType}/{endpointName}", pathParameters), 94 autorest.WithJSON(parameters), 95 autorest.WithQueryParameters(queryParameters)) 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 100// http.Response Body if it receives an error. 101func (client EndpointsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 102 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 103} 104 105// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 106// closes the http.Response Body. 107func (client EndpointsClient) CreateOrUpdateResponder(resp *http.Response) (result Endpoint, err error) { 108 err = autorest.Respond( 109 resp, 110 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 111 autorest.ByUnmarshallingJSON(&result), 112 autorest.ByClosing()) 113 result.Response = autorest.Response{Response: resp} 114 return 115} 116 117// Delete deletes a Traffic Manager endpoint. 118// Parameters: 119// resourceGroupName - the name of the resource group containing the Traffic Manager endpoint to be deleted. 120// profileName - the name of the Traffic Manager profile. 121// endpointType - the type of the Traffic Manager endpoint to be deleted. 122// endpointName - the name of the Traffic Manager endpoint to be deleted. 123func (client EndpointsClient) Delete(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string) (result autorest.Response, err error) { 124 if tracing.IsEnabled() { 125 ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.Delete") 126 defer func() { 127 sc := -1 128 if result.Response != nil { 129 sc = result.Response.StatusCode 130 } 131 tracing.EndSpan(ctx, sc, err) 132 }() 133 } 134 req, err := client.DeletePreparer(ctx, resourceGroupName, profileName, endpointType, endpointName) 135 if err != nil { 136 err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Delete", nil, "Failure preparing request") 137 return 138 } 139 140 resp, err := client.DeleteSender(req) 141 if err != nil { 142 result.Response = resp 143 err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Delete", resp, "Failure sending request") 144 return 145 } 146 147 result, err = client.DeleteResponder(resp) 148 if err != nil { 149 err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Delete", resp, "Failure responding to request") 150 return 151 } 152 153 return 154} 155 156// DeletePreparer prepares the Delete request. 157func (client EndpointsClient) DeletePreparer(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string) (*http.Request, error) { 158 pathParameters := map[string]interface{}{ 159 "endpointName": autorest.Encode("path", endpointName), 160 "endpointType": autorest.Encode("path", endpointType), 161 "profileName": autorest.Encode("path", profileName), 162 "resourceGroupName": autorest.Encode("path", resourceGroupName), 163 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 164 } 165 166 const APIVersion = "2015-11-01" 167 queryParameters := map[string]interface{}{ 168 "api-version": APIVersion, 169 } 170 171 preparer := autorest.CreatePreparer( 172 autorest.AsDelete(), 173 autorest.WithBaseURL(client.BaseURI), 174 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}/{endpointType}/{endpointName}", pathParameters), 175 autorest.WithQueryParameters(queryParameters)) 176 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 177} 178 179// DeleteSender sends the Delete request. The method will close the 180// http.Response Body if it receives an error. 181func (client EndpointsClient) DeleteSender(req *http.Request) (*http.Response, error) { 182 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 183} 184 185// DeleteResponder handles the response to the Delete request. The method always 186// closes the http.Response Body. 187func (client EndpointsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 188 err = autorest.Respond( 189 resp, 190 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 191 autorest.ByClosing()) 192 result.Response = resp 193 return 194} 195 196// Get gets a Traffic Manager endpoint. 197// Parameters: 198// resourceGroupName - the name of the resource group containing the Traffic Manager endpoint. 199// profileName - the name of the Traffic Manager profile. 200// endpointType - the type of the Traffic Manager endpoint. 201// endpointName - the name of the Traffic Manager endpoint. 202func (client EndpointsClient) Get(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string) (result Endpoint, err error) { 203 if tracing.IsEnabled() { 204 ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.Get") 205 defer func() { 206 sc := -1 207 if result.Response.Response != nil { 208 sc = result.Response.Response.StatusCode 209 } 210 tracing.EndSpan(ctx, sc, err) 211 }() 212 } 213 req, err := client.GetPreparer(ctx, resourceGroupName, profileName, endpointType, endpointName) 214 if err != nil { 215 err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Get", nil, "Failure preparing request") 216 return 217 } 218 219 resp, err := client.GetSender(req) 220 if err != nil { 221 result.Response = autorest.Response{Response: resp} 222 err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Get", resp, "Failure sending request") 223 return 224 } 225 226 result, err = client.GetResponder(resp) 227 if err != nil { 228 err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Get", resp, "Failure responding to request") 229 return 230 } 231 232 return 233} 234 235// GetPreparer prepares the Get request. 236func (client EndpointsClient) GetPreparer(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string) (*http.Request, error) { 237 pathParameters := map[string]interface{}{ 238 "endpointName": autorest.Encode("path", endpointName), 239 "endpointType": autorest.Encode("path", endpointType), 240 "profileName": autorest.Encode("path", profileName), 241 "resourceGroupName": autorest.Encode("path", resourceGroupName), 242 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 243 } 244 245 const APIVersion = "2015-11-01" 246 queryParameters := map[string]interface{}{ 247 "api-version": APIVersion, 248 } 249 250 preparer := autorest.CreatePreparer( 251 autorest.AsGet(), 252 autorest.WithBaseURL(client.BaseURI), 253 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}/{endpointType}/{endpointName}", pathParameters), 254 autorest.WithQueryParameters(queryParameters)) 255 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 256} 257 258// GetSender sends the Get request. The method will close the 259// http.Response Body if it receives an error. 260func (client EndpointsClient) GetSender(req *http.Request) (*http.Response, error) { 261 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 262} 263 264// GetResponder handles the response to the Get request. The method always 265// closes the http.Response Body. 266func (client EndpointsClient) GetResponder(resp *http.Response) (result Endpoint, err error) { 267 err = autorest.Respond( 268 resp, 269 azure.WithErrorUnlessStatusCode(http.StatusOK), 270 autorest.ByUnmarshallingJSON(&result), 271 autorest.ByClosing()) 272 result.Response = autorest.Response{Response: resp} 273 return 274} 275 276// Update update a Traffic Manager endpoint. 277// Parameters: 278// resourceGroupName - the name of the resource group containing the Traffic Manager endpoint to be updated. 279// profileName - the name of the Traffic Manager profile. 280// endpointType - the type of the Traffic Manager endpoint to be updated. 281// endpointName - the name of the Traffic Manager endpoint to be updated. 282// parameters - the Traffic Manager endpoint parameters supplied to the Update operation. 283func (client EndpointsClient) Update(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string, parameters Endpoint) (result Endpoint, err error) { 284 if tracing.IsEnabled() { 285 ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.Update") 286 defer func() { 287 sc := -1 288 if result.Response.Response != nil { 289 sc = result.Response.Response.StatusCode 290 } 291 tracing.EndSpan(ctx, sc, err) 292 }() 293 } 294 req, err := client.UpdatePreparer(ctx, resourceGroupName, profileName, endpointType, endpointName, parameters) 295 if err != nil { 296 err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Update", nil, "Failure preparing request") 297 return 298 } 299 300 resp, err := client.UpdateSender(req) 301 if err != nil { 302 result.Response = autorest.Response{Response: resp} 303 err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Update", resp, "Failure sending request") 304 return 305 } 306 307 result, err = client.UpdateResponder(resp) 308 if err != nil { 309 err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Update", resp, "Failure responding to request") 310 return 311 } 312 313 return 314} 315 316// UpdatePreparer prepares the Update request. 317func (client EndpointsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string, parameters Endpoint) (*http.Request, error) { 318 pathParameters := map[string]interface{}{ 319 "endpointName": autorest.Encode("path", endpointName), 320 "endpointType": autorest.Encode("path", endpointType), 321 "profileName": autorest.Encode("path", profileName), 322 "resourceGroupName": autorest.Encode("path", resourceGroupName), 323 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 324 } 325 326 const APIVersion = "2015-11-01" 327 queryParameters := map[string]interface{}{ 328 "api-version": APIVersion, 329 } 330 331 preparer := autorest.CreatePreparer( 332 autorest.AsContentType("application/json; charset=utf-8"), 333 autorest.AsPatch(), 334 autorest.WithBaseURL(client.BaseURI), 335 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}/{endpointType}/{endpointName}", pathParameters), 336 autorest.WithJSON(parameters), 337 autorest.WithQueryParameters(queryParameters)) 338 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 339} 340 341// UpdateSender sends the Update request. The method will close the 342// http.Response Body if it receives an error. 343func (client EndpointsClient) UpdateSender(req *http.Request) (*http.Response, error) { 344 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 345} 346 347// UpdateResponder handles the response to the Update request. The method always 348// closes the http.Response Body. 349func (client EndpointsClient) UpdateResponder(resp *http.Response) (result Endpoint, err error) { 350 err = autorest.Respond( 351 resp, 352 azure.WithErrorUnlessStatusCode(http.StatusOK), 353 autorest.ByUnmarshallingJSON(&result), 354 autorest.ByClosing()) 355 result.Response = autorest.Response{Response: resp} 356 return 357} 358