1package batch 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// LocationClient is the client for the Location methods of the Batch service. 18type LocationClient struct { 19 BaseClient 20} 21 22// NewLocationClient creates an instance of the LocationClient client. 23func NewLocationClient(subscriptionID string) LocationClient { 24 return NewLocationClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewLocationClientWithBaseURI creates an instance of the LocationClient 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 NewLocationClientWithBaseURI(baseURI string, subscriptionID string) LocationClient { 30 return LocationClient{NewWithBaseURI(baseURI, subscriptionID)} 31} 32 33// GetQuotas gets the Batch service quotas for the specified subscription at the given location. 34// Parameters: 35// locationName - the desired region for the quotas. 36func (client LocationClient) GetQuotas(ctx context.Context, locationName string) (result LocationQuota, err error) { 37 if tracing.IsEnabled() { 38 ctx = tracing.StartSpan(ctx, fqdn+"/LocationClient.GetQuotas") 39 defer func() { 40 sc := -1 41 if result.Response.Response != nil { 42 sc = result.Response.Response.StatusCode 43 } 44 tracing.EndSpan(ctx, sc, err) 45 }() 46 } 47 req, err := client.GetQuotasPreparer(ctx, locationName) 48 if err != nil { 49 err = autorest.NewErrorWithError(err, "batch.LocationClient", "GetQuotas", nil, "Failure preparing request") 50 return 51 } 52 53 resp, err := client.GetQuotasSender(req) 54 if err != nil { 55 result.Response = autorest.Response{Response: resp} 56 err = autorest.NewErrorWithError(err, "batch.LocationClient", "GetQuotas", resp, "Failure sending request") 57 return 58 } 59 60 result, err = client.GetQuotasResponder(resp) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "batch.LocationClient", "GetQuotas", resp, "Failure responding to request") 63 return 64 } 65 66 return 67} 68 69// GetQuotasPreparer prepares the GetQuotas request. 70func (client LocationClient) GetQuotasPreparer(ctx context.Context, locationName string) (*http.Request, error) { 71 pathParameters := map[string]interface{}{ 72 "locationName": autorest.Encode("path", locationName), 73 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 74 } 75 76 const APIVersion = "2015-12-01" 77 queryParameters := map[string]interface{}{ 78 "api-version": APIVersion, 79 } 80 81 preparer := autorest.CreatePreparer( 82 autorest.AsGet(), 83 autorest.WithBaseURL(client.BaseURI), 84 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Batch/locations/{locationName}/quotas", pathParameters), 85 autorest.WithQueryParameters(queryParameters)) 86 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 87} 88 89// GetQuotasSender sends the GetQuotas request. The method will close the 90// http.Response Body if it receives an error. 91func (client LocationClient) GetQuotasSender(req *http.Request) (*http.Response, error) { 92 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 93} 94 95// GetQuotasResponder handles the response to the GetQuotas request. The method always 96// closes the http.Response Body. 97func (client LocationClient) GetQuotasResponder(resp *http.Response) (result LocationQuota, err error) { 98 err = autorest.Respond( 99 resp, 100 azure.WithErrorUnlessStatusCode(http.StatusOK), 101 autorest.ByUnmarshallingJSON(&result), 102 autorest.ByClosing()) 103 result.Response = autorest.Response{Response: resp} 104 return 105} 106