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// ServiceObjectivesClient 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 ServiceObjectivesClient struct {
21	BaseClient
22}
23
24// NewServiceObjectivesClient creates an instance of the ServiceObjectivesClient client.
25func NewServiceObjectivesClient(subscriptionID string) ServiceObjectivesClient {
26	return NewServiceObjectivesClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewServiceObjectivesClientWithBaseURI creates an instance of the ServiceObjectivesClient 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 NewServiceObjectivesClientWithBaseURI(baseURI string, subscriptionID string) ServiceObjectivesClient {
33	return ServiceObjectivesClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// Get gets a database service objective.
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// serviceObjectiveName - the name of the service objective to retrieve.
42func (client ServiceObjectivesClient) Get(ctx context.Context, resourceGroupName string, serverName string, serviceObjectiveName string) (result ServiceObjective, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceObjectivesClient.Get")
45		defer func() {
46			sc := -1
47			if result.Response.Response != nil {
48				sc = result.Response.Response.StatusCode
49			}
50			tracing.EndSpan(ctx, sc, err)
51		}()
52	}
53	req, err := client.GetPreparer(ctx, resourceGroupName, serverName, serviceObjectiveName)
54	if err != nil {
55		err = autorest.NewErrorWithError(err, "sql.ServiceObjectivesClient", "Get", nil, "Failure preparing request")
56		return
57	}
58
59	resp, err := client.GetSender(req)
60	if err != nil {
61		result.Response = autorest.Response{Response: resp}
62		err = autorest.NewErrorWithError(err, "sql.ServiceObjectivesClient", "Get", resp, "Failure sending request")
63		return
64	}
65
66	result, err = client.GetResponder(resp)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "sql.ServiceObjectivesClient", "Get", resp, "Failure responding to request")
69		return
70	}
71
72	return
73}
74
75// GetPreparer prepares the Get request.
76func (client ServiceObjectivesClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, serviceObjectiveName string) (*http.Request, error) {
77	pathParameters := map[string]interface{}{
78		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
79		"serverName":           autorest.Encode("path", serverName),
80		"serviceObjectiveName": autorest.Encode("path", serviceObjectiveName),
81		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
82	}
83
84	const APIVersion = "2014-04-01"
85	queryParameters := map[string]interface{}{
86		"api-version": APIVersion,
87	}
88
89	preparer := autorest.CreatePreparer(
90		autorest.AsGet(),
91		autorest.WithBaseURL(client.BaseURI),
92		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives/{serviceObjectiveName}", pathParameters),
93		autorest.WithQueryParameters(queryParameters))
94	return preparer.Prepare((&http.Request{}).WithContext(ctx))
95}
96
97// GetSender sends the Get request. The method will close the
98// http.Response Body if it receives an error.
99func (client ServiceObjectivesClient) GetSender(req *http.Request) (*http.Response, error) {
100	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
101}
102
103// GetResponder handles the response to the Get request. The method always
104// closes the http.Response Body.
105func (client ServiceObjectivesClient) GetResponder(resp *http.Response) (result ServiceObjective, err error) {
106	err = autorest.Respond(
107		resp,
108		azure.WithErrorUnlessStatusCode(http.StatusOK),
109		autorest.ByUnmarshallingJSON(&result),
110		autorest.ByClosing())
111	result.Response = autorest.Response{Response: resp}
112	return
113}
114
115// ListByServer returns database service objectives.
116// Parameters:
117// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
118// from the Azure Resource Manager API or the portal.
119// serverName - the name of the server.
120func (client ServiceObjectivesClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result ServiceObjectiveListResult, err error) {
121	if tracing.IsEnabled() {
122		ctx = tracing.StartSpan(ctx, fqdn+"/ServiceObjectivesClient.ListByServer")
123		defer func() {
124			sc := -1
125			if result.Response.Response != nil {
126				sc = result.Response.Response.StatusCode
127			}
128			tracing.EndSpan(ctx, sc, err)
129		}()
130	}
131	req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName)
132	if err != nil {
133		err = autorest.NewErrorWithError(err, "sql.ServiceObjectivesClient", "ListByServer", nil, "Failure preparing request")
134		return
135	}
136
137	resp, err := client.ListByServerSender(req)
138	if err != nil {
139		result.Response = autorest.Response{Response: resp}
140		err = autorest.NewErrorWithError(err, "sql.ServiceObjectivesClient", "ListByServer", resp, "Failure sending request")
141		return
142	}
143
144	result, err = client.ListByServerResponder(resp)
145	if err != nil {
146		err = autorest.NewErrorWithError(err, "sql.ServiceObjectivesClient", "ListByServer", resp, "Failure responding to request")
147		return
148	}
149
150	return
151}
152
153// ListByServerPreparer prepares the ListByServer request.
154func (client ServiceObjectivesClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
155	pathParameters := map[string]interface{}{
156		"resourceGroupName": autorest.Encode("path", resourceGroupName),
157		"serverName":        autorest.Encode("path", serverName),
158		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
159	}
160
161	const APIVersion = "2014-04-01"
162	queryParameters := map[string]interface{}{
163		"api-version": APIVersion,
164	}
165
166	preparer := autorest.CreatePreparer(
167		autorest.AsGet(),
168		autorest.WithBaseURL(client.BaseURI),
169		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/serviceObjectives", pathParameters),
170		autorest.WithQueryParameters(queryParameters))
171	return preparer.Prepare((&http.Request{}).WithContext(ctx))
172}
173
174// ListByServerSender sends the ListByServer request. The method will close the
175// http.Response Body if it receives an error.
176func (client ServiceObjectivesClient) ListByServerSender(req *http.Request) (*http.Response, error) {
177	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
178}
179
180// ListByServerResponder handles the response to the ListByServer request. The method always
181// closes the http.Response Body.
182func (client ServiceObjectivesClient) ListByServerResponder(resp *http.Response) (result ServiceObjectiveListResult, err error) {
183	err = autorest.Respond(
184		resp,
185		azure.WithErrorUnlessStatusCode(http.StatusOK),
186		autorest.ByUnmarshallingJSON(&result),
187		autorest.ByClosing())
188	result.Response = autorest.Response{Response: resp}
189	return
190}
191