...

Source file src/github.com/Azure/azure-sdk-for-go/services/trafficmanager/mgmt/2017-03-01/trafficmanager/endpoints.go

Documentation: github.com/Azure/azure-sdk-for-go/services/trafficmanager/mgmt/2017-03-01/trafficmanager

     1  package 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  
     9  import (
    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.
    18  type EndpointsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewEndpointsClient creates an instance of the EndpointsClient client.
    23  func 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).
    29  func 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.
    41  func (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.
    75  func (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 = "2017-03-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.
   101  func (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.
   107  func (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.
   123  func (client EndpointsClient) Delete(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string) (result DeleteOperationResult, err error) {
   124  	if tracing.IsEnabled() {
   125  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.Delete")
   126  		defer func() {
   127  			sc := -1
   128  			if result.Response.Response != nil {
   129  				sc = result.Response.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 = autorest.Response{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.
   157  func (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 = "2017-03-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.
   181  func (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.
   187  func (client EndpointsClient) DeleteResponder(resp *http.Response) (result DeleteOperationResult, err error) {
   188  	err = autorest.Respond(
   189  		resp,
   190  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   191  		autorest.ByUnmarshallingJSON(&result),
   192  		autorest.ByClosing())
   193  	result.Response = autorest.Response{Response: resp}
   194  	return
   195  }
   196  
   197  // Get gets a Traffic Manager endpoint.
   198  // Parameters:
   199  // resourceGroupName - the name of the resource group containing the Traffic Manager endpoint.
   200  // profileName - the name of the Traffic Manager profile.
   201  // endpointType - the type of the Traffic Manager endpoint.
   202  // endpointName - the name of the Traffic Manager endpoint.
   203  func (client EndpointsClient) Get(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string) (result Endpoint, err error) {
   204  	if tracing.IsEnabled() {
   205  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.Get")
   206  		defer func() {
   207  			sc := -1
   208  			if result.Response.Response != nil {
   209  				sc = result.Response.Response.StatusCode
   210  			}
   211  			tracing.EndSpan(ctx, sc, err)
   212  		}()
   213  	}
   214  	req, err := client.GetPreparer(ctx, resourceGroupName, profileName, endpointType, endpointName)
   215  	if err != nil {
   216  		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Get", nil, "Failure preparing request")
   217  		return
   218  	}
   219  
   220  	resp, err := client.GetSender(req)
   221  	if err != nil {
   222  		result.Response = autorest.Response{Response: resp}
   223  		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Get", resp, "Failure sending request")
   224  		return
   225  	}
   226  
   227  	result, err = client.GetResponder(resp)
   228  	if err != nil {
   229  		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Get", resp, "Failure responding to request")
   230  		return
   231  	}
   232  
   233  	return
   234  }
   235  
   236  // GetPreparer prepares the Get request.
   237  func (client EndpointsClient) GetPreparer(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string) (*http.Request, error) {
   238  	pathParameters := map[string]interface{}{
   239  		"endpointName":      autorest.Encode("path", endpointName),
   240  		"endpointType":      autorest.Encode("path", endpointType),
   241  		"profileName":       autorest.Encode("path", profileName),
   242  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   243  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   244  	}
   245  
   246  	const APIVersion = "2017-03-01"
   247  	queryParameters := map[string]interface{}{
   248  		"api-version": APIVersion,
   249  	}
   250  
   251  	preparer := autorest.CreatePreparer(
   252  		autorest.AsGet(),
   253  		autorest.WithBaseURL(client.BaseURI),
   254  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}/{endpointType}/{endpointName}", pathParameters),
   255  		autorest.WithQueryParameters(queryParameters))
   256  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   257  }
   258  
   259  // GetSender sends the Get request. The method will close the
   260  // http.Response Body if it receives an error.
   261  func (client EndpointsClient) GetSender(req *http.Request) (*http.Response, error) {
   262  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   263  }
   264  
   265  // GetResponder handles the response to the Get request. The method always
   266  // closes the http.Response Body.
   267  func (client EndpointsClient) GetResponder(resp *http.Response) (result Endpoint, err error) {
   268  	err = autorest.Respond(
   269  		resp,
   270  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   271  		autorest.ByUnmarshallingJSON(&result),
   272  		autorest.ByClosing())
   273  	result.Response = autorest.Response{Response: resp}
   274  	return
   275  }
   276  
   277  // Update update a Traffic Manager endpoint.
   278  // Parameters:
   279  // resourceGroupName - the name of the resource group containing the Traffic Manager endpoint to be updated.
   280  // profileName - the name of the Traffic Manager profile.
   281  // endpointType - the type of the Traffic Manager endpoint to be updated.
   282  // endpointName - the name of the Traffic Manager endpoint to be updated.
   283  // parameters - the Traffic Manager endpoint parameters supplied to the Update operation.
   284  func (client EndpointsClient) Update(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string, parameters Endpoint) (result Endpoint, err error) {
   285  	if tracing.IsEnabled() {
   286  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.Update")
   287  		defer func() {
   288  			sc := -1
   289  			if result.Response.Response != nil {
   290  				sc = result.Response.Response.StatusCode
   291  			}
   292  			tracing.EndSpan(ctx, sc, err)
   293  		}()
   294  	}
   295  	req, err := client.UpdatePreparer(ctx, resourceGroupName, profileName, endpointType, endpointName, parameters)
   296  	if err != nil {
   297  		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Update", nil, "Failure preparing request")
   298  		return
   299  	}
   300  
   301  	resp, err := client.UpdateSender(req)
   302  	if err != nil {
   303  		result.Response = autorest.Response{Response: resp}
   304  		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Update", resp, "Failure sending request")
   305  		return
   306  	}
   307  
   308  	result, err = client.UpdateResponder(resp)
   309  	if err != nil {
   310  		err = autorest.NewErrorWithError(err, "trafficmanager.EndpointsClient", "Update", resp, "Failure responding to request")
   311  		return
   312  	}
   313  
   314  	return
   315  }
   316  
   317  // UpdatePreparer prepares the Update request.
   318  func (client EndpointsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, profileName string, endpointType string, endpointName string, parameters Endpoint) (*http.Request, error) {
   319  	pathParameters := map[string]interface{}{
   320  		"endpointName":      autorest.Encode("path", endpointName),
   321  		"endpointType":      autorest.Encode("path", endpointType),
   322  		"profileName":       autorest.Encode("path", profileName),
   323  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   324  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   325  	}
   326  
   327  	const APIVersion = "2017-03-01"
   328  	queryParameters := map[string]interface{}{
   329  		"api-version": APIVersion,
   330  	}
   331  
   332  	preparer := autorest.CreatePreparer(
   333  		autorest.AsContentType("application/json; charset=utf-8"),
   334  		autorest.AsPatch(),
   335  		autorest.WithBaseURL(client.BaseURI),
   336  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}/{endpointType}/{endpointName}", pathParameters),
   337  		autorest.WithJSON(parameters),
   338  		autorest.WithQueryParameters(queryParameters))
   339  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   340  }
   341  
   342  // UpdateSender sends the Update request. The method will close the
   343  // http.Response Body if it receives an error.
   344  func (client EndpointsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   345  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   346  }
   347  
   348  // UpdateResponder handles the response to the Update request. The method always
   349  // closes the http.Response Body.
   350  func (client EndpointsClient) UpdateResponder(resp *http.Response) (result Endpoint, err error) {
   351  	err = autorest.Respond(
   352  		resp,
   353  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   354  		autorest.ByUnmarshallingJSON(&result),
   355  		autorest.ByClosing())
   356  	result.Response = autorest.Response{Response: resp}
   357  	return
   358  }
   359  

View as plain text