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// OperationsHealthClient 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 OperationsHealthClient struct {
21	BaseClient
22}
23
24// NewOperationsHealthClient creates an instance of the OperationsHealthClient client.
25func NewOperationsHealthClient(subscriptionID string) OperationsHealthClient {
26	return NewOperationsHealthClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewOperationsHealthClientWithBaseURI creates an instance of the OperationsHealthClient 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 NewOperationsHealthClientWithBaseURI(baseURI string, subscriptionID string) OperationsHealthClient {
33	return OperationsHealthClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// ListByLocation gets a service operation health status.
37// Parameters:
38// locationName - the name of the region where the resource is located.
39func (client OperationsHealthClient) ListByLocation(ctx context.Context, locationName string) (result OperationsHealthListResultPage, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsHealthClient.ListByLocation")
42		defer func() {
43			sc := -1
44			if result.ohlr.Response.Response != nil {
45				sc = result.ohlr.Response.Response.StatusCode
46			}
47			tracing.EndSpan(ctx, sc, err)
48		}()
49	}
50	result.fn = client.listByLocationNextResults
51	req, err := client.ListByLocationPreparer(ctx, locationName)
52	if err != nil {
53		err = autorest.NewErrorWithError(err, "sql.OperationsHealthClient", "ListByLocation", nil, "Failure preparing request")
54		return
55	}
56
57	resp, err := client.ListByLocationSender(req)
58	if err != nil {
59		result.ohlr.Response = autorest.Response{Response: resp}
60		err = autorest.NewErrorWithError(err, "sql.OperationsHealthClient", "ListByLocation", resp, "Failure sending request")
61		return
62	}
63
64	result.ohlr, err = client.ListByLocationResponder(resp)
65	if err != nil {
66		err = autorest.NewErrorWithError(err, "sql.OperationsHealthClient", "ListByLocation", resp, "Failure responding to request")
67		return
68	}
69	if result.ohlr.hasNextLink() && result.ohlr.IsEmpty() {
70		err = result.NextWithContext(ctx)
71		return
72	}
73
74	return
75}
76
77// ListByLocationPreparer prepares the ListByLocation request.
78func (client OperationsHealthClient) ListByLocationPreparer(ctx context.Context, locationName string) (*http.Request, error) {
79	pathParameters := map[string]interface{}{
80		"locationName":   autorest.Encode("path", locationName),
81		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
82	}
83
84	const APIVersion = "2020-11-01-preview"
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}/providers/Microsoft.Sql/locations/{locationName}/operationsHealth", pathParameters),
93		autorest.WithQueryParameters(queryParameters))
94	return preparer.Prepare((&http.Request{}).WithContext(ctx))
95}
96
97// ListByLocationSender sends the ListByLocation request. The method will close the
98// http.Response Body if it receives an error.
99func (client OperationsHealthClient) ListByLocationSender(req *http.Request) (*http.Response, error) {
100	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
101}
102
103// ListByLocationResponder handles the response to the ListByLocation request. The method always
104// closes the http.Response Body.
105func (client OperationsHealthClient) ListByLocationResponder(resp *http.Response) (result OperationsHealthListResult, 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// listByLocationNextResults retrieves the next set of results, if any.
116func (client OperationsHealthClient) listByLocationNextResults(ctx context.Context, lastResults OperationsHealthListResult) (result OperationsHealthListResult, err error) {
117	req, err := lastResults.operationsHealthListResultPreparer(ctx)
118	if err != nil {
119		return result, autorest.NewErrorWithError(err, "sql.OperationsHealthClient", "listByLocationNextResults", nil, "Failure preparing next results request")
120	}
121	if req == nil {
122		return
123	}
124	resp, err := client.ListByLocationSender(req)
125	if err != nil {
126		result.Response = autorest.Response{Response: resp}
127		return result, autorest.NewErrorWithError(err, "sql.OperationsHealthClient", "listByLocationNextResults", resp, "Failure sending next results request")
128	}
129	result, err = client.ListByLocationResponder(resp)
130	if err != nil {
131		err = autorest.NewErrorWithError(err, "sql.OperationsHealthClient", "listByLocationNextResults", resp, "Failure responding to next results request")
132	}
133	return
134}
135
136// ListByLocationComplete enumerates all values, automatically crossing page boundaries as required.
137func (client OperationsHealthClient) ListByLocationComplete(ctx context.Context, locationName string) (result OperationsHealthListResultIterator, err error) {
138	if tracing.IsEnabled() {
139		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsHealthClient.ListByLocation")
140		defer func() {
141			sc := -1
142			if result.Response().Response.Response != nil {
143				sc = result.page.Response().Response.Response.StatusCode
144			}
145			tracing.EndSpan(ctx, sc, err)
146		}()
147	}
148	result.page, err = client.ListByLocation(ctx, locationName)
149	return
150}
151