1package sql 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// ServerUsagesClient is the the Azure SQL Database management API provides a RESTful set of web services that interact 18// with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, and 19// delete databases. 20type ServerUsagesClient struct { 21 BaseClient 22} 23 24// NewServerUsagesClient creates an instance of the ServerUsagesClient client. 25func NewServerUsagesClient(subscriptionID string) ServerUsagesClient { 26 return NewServerUsagesClientWithBaseURI(DefaultBaseURI, subscriptionID) 27} 28 29// NewServerUsagesClientWithBaseURI creates an instance of the ServerUsagesClient client using a custom endpoint. Use 30// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 31func NewServerUsagesClientWithBaseURI(baseURI string, subscriptionID string) ServerUsagesClient { 32 return ServerUsagesClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// ListByServer returns server usages. 36// Parameters: 37// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 38// from the Azure Resource Manager API or the portal. 39// serverName - the name of the server. 40func (client ServerUsagesClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result ServerUsageListResult, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/ServerUsagesClient.ListByServer") 43 defer func() { 44 sc := -1 45 if result.Response.Response != nil { 46 sc = result.Response.Response.StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName) 52 if err != nil { 53 err = autorest.NewErrorWithError(err, "sql.ServerUsagesClient", "ListByServer", nil, "Failure preparing request") 54 return 55 } 56 57 resp, err := client.ListByServerSender(req) 58 if err != nil { 59 result.Response = autorest.Response{Response: resp} 60 err = autorest.NewErrorWithError(err, "sql.ServerUsagesClient", "ListByServer", resp, "Failure sending request") 61 return 62 } 63 64 result, err = client.ListByServerResponder(resp) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "sql.ServerUsagesClient", "ListByServer", resp, "Failure responding to request") 67 return 68 } 69 70 return 71} 72 73// ListByServerPreparer prepares the ListByServer request. 74func (client ServerUsagesClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 75 pathParameters := map[string]interface{}{ 76 "resourceGroupName": autorest.Encode("path", resourceGroupName), 77 "serverName": autorest.Encode("path", serverName), 78 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 79 } 80 81 const APIVersion = "2014-04-01" 82 queryParameters := map[string]interface{}{ 83 "api-version": APIVersion, 84 } 85 86 preparer := autorest.CreatePreparer( 87 autorest.AsGet(), 88 autorest.WithBaseURL(client.BaseURI), 89 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/usages", pathParameters), 90 autorest.WithQueryParameters(queryParameters)) 91 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 92} 93 94// ListByServerSender sends the ListByServer request. The method will close the 95// http.Response Body if it receives an error. 96func (client ServerUsagesClient) ListByServerSender(req *http.Request) (*http.Response, error) { 97 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 98} 99 100// ListByServerResponder handles the response to the ListByServer request. The method always 101// closes the http.Response Body. 102func (client ServerUsagesClient) ListByServerResponder(resp *http.Response) (result ServerUsageListResult, err error) { 103 err = autorest.Respond( 104 resp, 105 azure.WithErrorUnlessStatusCode(http.StatusOK), 106 autorest.ByUnmarshallingJSON(&result), 107 autorest.ByClosing()) 108 result.Response = autorest.Response{Response: resp} 109 return 110} 111