1package mariadb 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/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// QueryTextsClient is the the Microsoft Azure management API provides create, read, update, and delete functionality 19// for Azure MariaDB resources including servers, databases, firewall rules, VNET rules, log files and configurations 20// with new business model. 21type QueryTextsClient struct { 22 BaseClient 23} 24 25// NewQueryTextsClient creates an instance of the QueryTextsClient client. 26func NewQueryTextsClient(subscriptionID string) QueryTextsClient { 27 return NewQueryTextsClientWithBaseURI(DefaultBaseURI, subscriptionID) 28} 29 30// NewQueryTextsClientWithBaseURI creates an instance of the QueryTextsClient client using a custom endpoint. Use this 31// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 32func NewQueryTextsClientWithBaseURI(baseURI string, subscriptionID string) QueryTextsClient { 33 return QueryTextsClient{NewWithBaseURI(baseURI, subscriptionID)} 34} 35 36// Get retrieve the Query-Store query texts for the queryId. 37// Parameters: 38// resourceGroupName - the name of the resource group. The name is case insensitive. 39// serverName - the name of the server. 40// queryID - the Query-Store query identifier. 41func (client QueryTextsClient) Get(ctx context.Context, resourceGroupName string, serverName string, queryID string) (result QueryText, err error) { 42 if tracing.IsEnabled() { 43 ctx = tracing.StartSpan(ctx, fqdn+"/QueryTextsClient.Get") 44 defer func() { 45 sc := -1 46 if result.Response.Response != nil { 47 sc = result.Response.Response.StatusCode 48 } 49 tracing.EndSpan(ctx, sc, err) 50 }() 51 } 52 if err := validation.Validate([]validation.Validation{ 53 {TargetValue: client.SubscriptionID, 54 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 55 {TargetValue: resourceGroupName, 56 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 57 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 58 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 59 return result, validation.NewError("mariadb.QueryTextsClient", "Get", err.Error()) 60 } 61 62 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, queryID) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "mariadb.QueryTextsClient", "Get", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.GetSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "mariadb.QueryTextsClient", "Get", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.GetResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "mariadb.QueryTextsClient", "Get", resp, "Failure responding to request") 78 return 79 } 80 81 return 82} 83 84// GetPreparer prepares the Get request. 85func (client QueryTextsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, queryID string) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "queryId": autorest.Encode("path", queryID), 88 "resourceGroupName": autorest.Encode("path", resourceGroupName), 89 "serverName": autorest.Encode("path", serverName), 90 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 91 } 92 93 const APIVersion = "2018-06-01" 94 queryParameters := map[string]interface{}{ 95 "api-version": APIVersion, 96 } 97 98 preparer := autorest.CreatePreparer( 99 autorest.AsGet(), 100 autorest.WithBaseURL(client.BaseURI), 101 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMariaDB/servers/{serverName}/queryTexts/{queryId}", pathParameters), 102 autorest.WithQueryParameters(queryParameters)) 103 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 104} 105 106// GetSender sends the Get request. The method will close the 107// http.Response Body if it receives an error. 108func (client QueryTextsClient) GetSender(req *http.Request) (*http.Response, error) { 109 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 110} 111 112// GetResponder handles the response to the Get request. The method always 113// closes the http.Response Body. 114func (client QueryTextsClient) GetResponder(resp *http.Response) (result QueryText, err error) { 115 err = autorest.Respond( 116 resp, 117 azure.WithErrorUnlessStatusCode(http.StatusOK), 118 autorest.ByUnmarshallingJSON(&result), 119 autorest.ByClosing()) 120 result.Response = autorest.Response{Response: resp} 121 return 122} 123 124// ListByServer retrieve the Query-Store query texts for specified queryIds. 125// Parameters: 126// resourceGroupName - the name of the resource group. The name is case insensitive. 127// serverName - the name of the server. 128// queryIds - the query identifiers 129func (client QueryTextsClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string, queryIds []string) (result QueryTextsResultListPage, err error) { 130 if tracing.IsEnabled() { 131 ctx = tracing.StartSpan(ctx, fqdn+"/QueryTextsClient.ListByServer") 132 defer func() { 133 sc := -1 134 if result.qtrl.Response.Response != nil { 135 sc = result.qtrl.Response.Response.StatusCode 136 } 137 tracing.EndSpan(ctx, sc, err) 138 }() 139 } 140 if err := validation.Validate([]validation.Validation{ 141 {TargetValue: client.SubscriptionID, 142 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 143 {TargetValue: resourceGroupName, 144 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 145 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 146 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 147 {TargetValue: queryIds, 148 Constraints: []validation.Constraint{{Target: "queryIds", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 149 return result, validation.NewError("mariadb.QueryTextsClient", "ListByServer", err.Error()) 150 } 151 152 result.fn = client.listByServerNextResults 153 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName, queryIds) 154 if err != nil { 155 err = autorest.NewErrorWithError(err, "mariadb.QueryTextsClient", "ListByServer", nil, "Failure preparing request") 156 return 157 } 158 159 resp, err := client.ListByServerSender(req) 160 if err != nil { 161 result.qtrl.Response = autorest.Response{Response: resp} 162 err = autorest.NewErrorWithError(err, "mariadb.QueryTextsClient", "ListByServer", resp, "Failure sending request") 163 return 164 } 165 166 result.qtrl, err = client.ListByServerResponder(resp) 167 if err != nil { 168 err = autorest.NewErrorWithError(err, "mariadb.QueryTextsClient", "ListByServer", resp, "Failure responding to request") 169 return 170 } 171 if result.qtrl.hasNextLink() && result.qtrl.IsEmpty() { 172 err = result.NextWithContext(ctx) 173 return 174 } 175 176 return 177} 178 179// ListByServerPreparer prepares the ListByServer request. 180func (client QueryTextsClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string, queryIds []string) (*http.Request, error) { 181 pathParameters := map[string]interface{}{ 182 "resourceGroupName": autorest.Encode("path", resourceGroupName), 183 "serverName": autorest.Encode("path", serverName), 184 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 185 } 186 187 const APIVersion = "2018-06-01" 188 queryParameters := map[string]interface{}{ 189 "api-version": APIVersion, 190 "queryIds": queryIds, 191 } 192 193 preparer := autorest.CreatePreparer( 194 autorest.AsGet(), 195 autorest.WithBaseURL(client.BaseURI), 196 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMariaDB/servers/{serverName}/queryTexts", pathParameters), 197 autorest.WithQueryParameters(queryParameters)) 198 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 199} 200 201// ListByServerSender sends the ListByServer request. The method will close the 202// http.Response Body if it receives an error. 203func (client QueryTextsClient) ListByServerSender(req *http.Request) (*http.Response, error) { 204 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 205} 206 207// ListByServerResponder handles the response to the ListByServer request. The method always 208// closes the http.Response Body. 209func (client QueryTextsClient) ListByServerResponder(resp *http.Response) (result QueryTextsResultList, err error) { 210 err = autorest.Respond( 211 resp, 212 azure.WithErrorUnlessStatusCode(http.StatusOK), 213 autorest.ByUnmarshallingJSON(&result), 214 autorest.ByClosing()) 215 result.Response = autorest.Response{Response: resp} 216 return 217} 218 219// listByServerNextResults retrieves the next set of results, if any. 220func (client QueryTextsClient) listByServerNextResults(ctx context.Context, lastResults QueryTextsResultList) (result QueryTextsResultList, err error) { 221 req, err := lastResults.queryTextsResultListPreparer(ctx) 222 if err != nil { 223 return result, autorest.NewErrorWithError(err, "mariadb.QueryTextsClient", "listByServerNextResults", nil, "Failure preparing next results request") 224 } 225 if req == nil { 226 return 227 } 228 resp, err := client.ListByServerSender(req) 229 if err != nil { 230 result.Response = autorest.Response{Response: resp} 231 return result, autorest.NewErrorWithError(err, "mariadb.QueryTextsClient", "listByServerNextResults", resp, "Failure sending next results request") 232 } 233 result, err = client.ListByServerResponder(resp) 234 if err != nil { 235 err = autorest.NewErrorWithError(err, "mariadb.QueryTextsClient", "listByServerNextResults", resp, "Failure responding to next results request") 236 } 237 return 238} 239 240// ListByServerComplete enumerates all values, automatically crossing page boundaries as required. 241func (client QueryTextsClient) ListByServerComplete(ctx context.Context, resourceGroupName string, serverName string, queryIds []string) (result QueryTextsResultListIterator, err error) { 242 if tracing.IsEnabled() { 243 ctx = tracing.StartSpan(ctx, fqdn+"/QueryTextsClient.ListByServer") 244 defer func() { 245 sc := -1 246 if result.Response().Response.Response != nil { 247 sc = result.page.Response().Response.Response.StatusCode 248 } 249 tracing.EndSpan(ctx, sc, err) 250 }() 251 } 252 result.page, err = client.ListByServer(ctx, resourceGroupName, serverName, queryIds) 253 return 254} 255