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// ServiceTierAdvisorsClient is the the Azure SQL Database management API provides a RESTful set of web services that 18// interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, 19// and delete databases. 20type ServiceTierAdvisorsClient struct { 21 BaseClient 22} 23 24// NewServiceTierAdvisorsClient creates an instance of the ServiceTierAdvisorsClient client. 25func NewServiceTierAdvisorsClient(subscriptionID string) ServiceTierAdvisorsClient { 26 return NewServiceTierAdvisorsClientWithBaseURI(DefaultBaseURI, subscriptionID) 27} 28 29// NewServiceTierAdvisorsClientWithBaseURI creates an instance of the ServiceTierAdvisorsClient client using a custom 30// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 31// stack). 32func NewServiceTierAdvisorsClientWithBaseURI(baseURI string, subscriptionID string) ServiceTierAdvisorsClient { 33 return ServiceTierAdvisorsClient{NewWithBaseURI(baseURI, subscriptionID)} 34} 35 36// Get gets a service tier advisor. 37// Parameters: 38// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 39// from the Azure Resource Manager API or the portal. 40// serverName - the name of the server. 41// databaseName - the name of database. 42// serviceTierAdvisorName - the name of service tier advisor. 43func (client ServiceTierAdvisorsClient) Get(ctx context.Context, resourceGroupName string, serverName string, databaseName string, serviceTierAdvisorName string) (result ServiceTierAdvisor, err error) { 44 if tracing.IsEnabled() { 45 ctx = tracing.StartSpan(ctx, fqdn+"/ServiceTierAdvisorsClient.Get") 46 defer func() { 47 sc := -1 48 if result.Response.Response != nil { 49 sc = result.Response.Response.StatusCode 50 } 51 tracing.EndSpan(ctx, sc, err) 52 }() 53 } 54 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, databaseName, serviceTierAdvisorName) 55 if err != nil { 56 err = autorest.NewErrorWithError(err, "sql.ServiceTierAdvisorsClient", "Get", nil, "Failure preparing request") 57 return 58 } 59 60 resp, err := client.GetSender(req) 61 if err != nil { 62 result.Response = autorest.Response{Response: resp} 63 err = autorest.NewErrorWithError(err, "sql.ServiceTierAdvisorsClient", "Get", resp, "Failure sending request") 64 return 65 } 66 67 result, err = client.GetResponder(resp) 68 if err != nil { 69 err = autorest.NewErrorWithError(err, "sql.ServiceTierAdvisorsClient", "Get", resp, "Failure responding to request") 70 return 71 } 72 73 return 74} 75 76// GetPreparer prepares the Get request. 77func (client ServiceTierAdvisorsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, serviceTierAdvisorName string) (*http.Request, error) { 78 pathParameters := map[string]interface{}{ 79 "databaseName": autorest.Encode("path", databaseName), 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "serverName": autorest.Encode("path", serverName), 82 "serviceTierAdvisorName": autorest.Encode("path", serviceTierAdvisorName), 83 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 84 } 85 86 const APIVersion = "2014-04-01" 87 queryParameters := map[string]interface{}{ 88 "api-version": APIVersion, 89 } 90 91 preparer := autorest.CreatePreparer( 92 autorest.AsGet(), 93 autorest.WithBaseURL(client.BaseURI), 94 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/serviceTierAdvisors/{serviceTierAdvisorName}", pathParameters), 95 autorest.WithQueryParameters(queryParameters)) 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// GetSender sends the Get request. The method will close the 100// http.Response Body if it receives an error. 101func (client ServiceTierAdvisorsClient) GetSender(req *http.Request) (*http.Response, error) { 102 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 103} 104 105// GetResponder handles the response to the Get request. The method always 106// closes the http.Response Body. 107func (client ServiceTierAdvisorsClient) GetResponder(resp *http.Response) (result ServiceTierAdvisor, err error) { 108 err = autorest.Respond( 109 resp, 110 azure.WithErrorUnlessStatusCode(http.StatusOK), 111 autorest.ByUnmarshallingJSON(&result), 112 autorest.ByClosing()) 113 result.Response = autorest.Response{Response: resp} 114 return 115} 116 117// ListByDatabase returns service tier advisors for specified database. 118// Parameters: 119// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 120// from the Azure Resource Manager API or the portal. 121// serverName - the name of the server. 122// databaseName - the name of database. 123func (client ServiceTierAdvisorsClient) ListByDatabase(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result ServiceTierAdvisorListResult, err error) { 124 if tracing.IsEnabled() { 125 ctx = tracing.StartSpan(ctx, fqdn+"/ServiceTierAdvisorsClient.ListByDatabase") 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.ListByDatabasePreparer(ctx, resourceGroupName, serverName, databaseName) 135 if err != nil { 136 err = autorest.NewErrorWithError(err, "sql.ServiceTierAdvisorsClient", "ListByDatabase", nil, "Failure preparing request") 137 return 138 } 139 140 resp, err := client.ListByDatabaseSender(req) 141 if err != nil { 142 result.Response = autorest.Response{Response: resp} 143 err = autorest.NewErrorWithError(err, "sql.ServiceTierAdvisorsClient", "ListByDatabase", resp, "Failure sending request") 144 return 145 } 146 147 result, err = client.ListByDatabaseResponder(resp) 148 if err != nil { 149 err = autorest.NewErrorWithError(err, "sql.ServiceTierAdvisorsClient", "ListByDatabase", resp, "Failure responding to request") 150 return 151 } 152 153 return 154} 155 156// ListByDatabasePreparer prepares the ListByDatabase request. 157func (client ServiceTierAdvisorsClient) ListByDatabasePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) { 158 pathParameters := map[string]interface{}{ 159 "databaseName": autorest.Encode("path", databaseName), 160 "resourceGroupName": autorest.Encode("path", resourceGroupName), 161 "serverName": autorest.Encode("path", serverName), 162 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 163 } 164 165 const APIVersion = "2014-04-01" 166 queryParameters := map[string]interface{}{ 167 "api-version": APIVersion, 168 } 169 170 preparer := autorest.CreatePreparer( 171 autorest.AsGet(), 172 autorest.WithBaseURL(client.BaseURI), 173 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/serviceTierAdvisors", pathParameters), 174 autorest.WithQueryParameters(queryParameters)) 175 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 176} 177 178// ListByDatabaseSender sends the ListByDatabase request. The method will close the 179// http.Response Body if it receives an error. 180func (client ServiceTierAdvisorsClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) { 181 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 182} 183 184// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always 185// closes the http.Response Body. 186func (client ServiceTierAdvisorsClient) ListByDatabaseResponder(resp *http.Response) (result ServiceTierAdvisorListResult, err error) { 187 err = autorest.Respond( 188 resp, 189 azure.WithErrorUnlessStatusCode(http.StatusOK), 190 autorest.ByUnmarshallingJSON(&result), 191 autorest.ByClosing()) 192 result.Response = autorest.Response{Response: resp} 193 return 194} 195