1package sql 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// ServerUsagesClient is the the Azure SQL Database management API provides a RESTful set of web services that interact 29// with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, and 30// delete databases. 31type ServerUsagesClient struct { 32 BaseClient 33} 34 35// NewServerUsagesClient creates an instance of the ServerUsagesClient client. 36func NewServerUsagesClient(subscriptionID string) ServerUsagesClient { 37 return NewServerUsagesClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewServerUsagesClientWithBaseURI creates an instance of the ServerUsagesClient client using a custom endpoint. Use 41// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 42func NewServerUsagesClientWithBaseURI(baseURI string, subscriptionID string) ServerUsagesClient { 43 return ServerUsagesClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// ListByServer returns server usages. 47// Parameters: 48// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 49// from the Azure Resource Manager API or the portal. 50// serverName - the name of the server. 51func (client ServerUsagesClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result ServerUsageListResult, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/ServerUsagesClient.ListByServer") 54 defer func() { 55 sc := -1 56 if result.Response.Response != nil { 57 sc = result.Response.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "sql.ServerUsagesClient", "ListByServer", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.ListByServerSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "sql.ServerUsagesClient", "ListByServer", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.ListByServerResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "sql.ServerUsagesClient", "ListByServer", resp, "Failure responding to request") 78 } 79 80 return 81} 82 83// ListByServerPreparer prepares the ListByServer request. 84func (client ServerUsagesClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 85 pathParameters := map[string]interface{}{ 86 "resourceGroupName": autorest.Encode("path", resourceGroupName), 87 "serverName": autorest.Encode("path", serverName), 88 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 89 } 90 91 const APIVersion = "2014-04-01" 92 queryParameters := map[string]interface{}{ 93 "api-version": APIVersion, 94 } 95 96 preparer := autorest.CreatePreparer( 97 autorest.AsGet(), 98 autorest.WithBaseURL(client.BaseURI), 99 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/usages", pathParameters), 100 autorest.WithQueryParameters(queryParameters)) 101 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 102} 103 104// ListByServerSender sends the ListByServer request. The method will close the 105// http.Response Body if it receives an error. 106func (client ServerUsagesClient) ListByServerSender(req *http.Request) (*http.Response, error) { 107 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 108} 109 110// ListByServerResponder handles the response to the ListByServer request. The method always 111// closes the http.Response Body. 112func (client ServerUsagesClient) ListByServerResponder(resp *http.Response) (result ServerUsageListResult, err error) { 113 err = autorest.Respond( 114 resp, 115 client.ByInspecting(), 116 azure.WithErrorUnlessStatusCode(http.StatusOK), 117 autorest.ByUnmarshallingJSON(&result), 118 autorest.ByClosing()) 119 result.Response = autorest.Response{Response: resp} 120 return 121} 122