1package redis 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// LinkedServerClient is the REST API for Azure Redis Cache Service. 19type LinkedServerClient struct { 20 BaseClient 21} 22 23// NewLinkedServerClient creates an instance of the LinkedServerClient client. 24func NewLinkedServerClient(subscriptionID string) LinkedServerClient { 25 return NewLinkedServerClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewLinkedServerClientWithBaseURI creates an instance of the LinkedServerClient client using a custom endpoint. Use 29// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewLinkedServerClientWithBaseURI(baseURI string, subscriptionID string) LinkedServerClient { 31 return LinkedServerClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// Create adds a linked server to the Redis cache (requires Premium SKU). 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// name - the name of the Redis cache. 38// linkedServerName - the name of the linked server that is being added to the Redis cache. 39// parameters - parameters supplied to the Create Linked server operation. 40func (client LinkedServerClient) Create(ctx context.Context, resourceGroupName string, name string, linkedServerName string, parameters LinkedServerCreateParameters) (result LinkedServerCreateFuture, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/LinkedServerClient.Create") 43 defer func() { 44 sc := -1 45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 46 sc = result.FutureAPI.Response().StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 if err := validation.Validate([]validation.Validation{ 52 {TargetValue: parameters, 53 Constraints: []validation.Constraint{{Target: "parameters.LinkedServerCreateProperties", Name: validation.Null, Rule: true, 54 Chain: []validation.Constraint{{Target: "parameters.LinkedServerCreateProperties.LinkedRedisCacheID", Name: validation.Null, Rule: true, Chain: nil}, 55 {Target: "parameters.LinkedServerCreateProperties.LinkedRedisCacheLocation", Name: validation.Null, Rule: true, Chain: nil}, 56 }}}}}); err != nil { 57 return result, validation.NewError("redis.LinkedServerClient", "Create", err.Error()) 58 } 59 60 req, err := client.CreatePreparer(ctx, resourceGroupName, name, linkedServerName, parameters) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "redis.LinkedServerClient", "Create", nil, "Failure preparing request") 63 return 64 } 65 66 result, err = client.CreateSender(req) 67 if err != nil { 68 err = autorest.NewErrorWithError(err, "redis.LinkedServerClient", "Create", nil, "Failure sending request") 69 return 70 } 71 72 return 73} 74 75// CreatePreparer prepares the Create request. 76func (client LinkedServerClient) CreatePreparer(ctx context.Context, resourceGroupName string, name string, linkedServerName string, parameters LinkedServerCreateParameters) (*http.Request, error) { 77 pathParameters := map[string]interface{}{ 78 "linkedServerName": autorest.Encode("path", linkedServerName), 79 "name": autorest.Encode("path", name), 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 82 } 83 84 const APIVersion = "2020-06-01" 85 queryParameters := map[string]interface{}{ 86 "api-version": APIVersion, 87 } 88 89 preparer := autorest.CreatePreparer( 90 autorest.AsContentType("application/json; charset=utf-8"), 91 autorest.AsPut(), 92 autorest.WithBaseURL(client.BaseURI), 93 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/redis/{name}/linkedServers/{linkedServerName}", pathParameters), 94 autorest.WithJSON(parameters), 95 autorest.WithQueryParameters(queryParameters)) 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// CreateSender sends the Create request. The method will close the 100// http.Response Body if it receives an error. 101func (client LinkedServerClient) CreateSender(req *http.Request) (future LinkedServerCreateFuture, err error) { 102 var resp *http.Response 103 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 104 if err != nil { 105 return 106 } 107 var azf azure.Future 108 azf, err = azure.NewFutureFromResponse(resp) 109 future.FutureAPI = &azf 110 future.Result = future.result 111 return 112} 113 114// CreateResponder handles the response to the Create request. The method always 115// closes the http.Response Body. 116func (client LinkedServerClient) CreateResponder(resp *http.Response) (result LinkedServerWithProperties, err error) { 117 err = autorest.Respond( 118 resp, 119 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 120 autorest.ByUnmarshallingJSON(&result), 121 autorest.ByClosing()) 122 result.Response = autorest.Response{Response: resp} 123 return 124} 125 126// Delete deletes the linked server from a redis cache (requires Premium SKU). 127// Parameters: 128// resourceGroupName - the name of the resource group. 129// name - the name of the redis cache. 130// linkedServerName - the name of the linked server that is being added to the Redis cache. 131func (client LinkedServerClient) Delete(ctx context.Context, resourceGroupName string, name string, linkedServerName string) (result autorest.Response, err error) { 132 if tracing.IsEnabled() { 133 ctx = tracing.StartSpan(ctx, fqdn+"/LinkedServerClient.Delete") 134 defer func() { 135 sc := -1 136 if result.Response != nil { 137 sc = result.Response.StatusCode 138 } 139 tracing.EndSpan(ctx, sc, err) 140 }() 141 } 142 req, err := client.DeletePreparer(ctx, resourceGroupName, name, linkedServerName) 143 if err != nil { 144 err = autorest.NewErrorWithError(err, "redis.LinkedServerClient", "Delete", nil, "Failure preparing request") 145 return 146 } 147 148 resp, err := client.DeleteSender(req) 149 if err != nil { 150 result.Response = resp 151 err = autorest.NewErrorWithError(err, "redis.LinkedServerClient", "Delete", resp, "Failure sending request") 152 return 153 } 154 155 result, err = client.DeleteResponder(resp) 156 if err != nil { 157 err = autorest.NewErrorWithError(err, "redis.LinkedServerClient", "Delete", resp, "Failure responding to request") 158 return 159 } 160 161 return 162} 163 164// DeletePreparer prepares the Delete request. 165func (client LinkedServerClient) DeletePreparer(ctx context.Context, resourceGroupName string, name string, linkedServerName string) (*http.Request, error) { 166 pathParameters := map[string]interface{}{ 167 "linkedServerName": autorest.Encode("path", linkedServerName), 168 "name": autorest.Encode("path", name), 169 "resourceGroupName": autorest.Encode("path", resourceGroupName), 170 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 171 } 172 173 const APIVersion = "2020-06-01" 174 queryParameters := map[string]interface{}{ 175 "api-version": APIVersion, 176 } 177 178 preparer := autorest.CreatePreparer( 179 autorest.AsDelete(), 180 autorest.WithBaseURL(client.BaseURI), 181 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/redis/{name}/linkedServers/{linkedServerName}", pathParameters), 182 autorest.WithQueryParameters(queryParameters)) 183 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 184} 185 186// DeleteSender sends the Delete request. The method will close the 187// http.Response Body if it receives an error. 188func (client LinkedServerClient) DeleteSender(req *http.Request) (*http.Response, error) { 189 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 190} 191 192// DeleteResponder handles the response to the Delete request. The method always 193// closes the http.Response Body. 194func (client LinkedServerClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 195 err = autorest.Respond( 196 resp, 197 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 198 autorest.ByClosing()) 199 result.Response = resp 200 return 201} 202 203// Get gets the detailed information about a linked server of a redis cache (requires Premium SKU). 204// Parameters: 205// resourceGroupName - the name of the resource group. 206// name - the name of the redis cache. 207// linkedServerName - the name of the linked server. 208func (client LinkedServerClient) Get(ctx context.Context, resourceGroupName string, name string, linkedServerName string) (result LinkedServerWithProperties, err error) { 209 if tracing.IsEnabled() { 210 ctx = tracing.StartSpan(ctx, fqdn+"/LinkedServerClient.Get") 211 defer func() { 212 sc := -1 213 if result.Response.Response != nil { 214 sc = result.Response.Response.StatusCode 215 } 216 tracing.EndSpan(ctx, sc, err) 217 }() 218 } 219 req, err := client.GetPreparer(ctx, resourceGroupName, name, linkedServerName) 220 if err != nil { 221 err = autorest.NewErrorWithError(err, "redis.LinkedServerClient", "Get", nil, "Failure preparing request") 222 return 223 } 224 225 resp, err := client.GetSender(req) 226 if err != nil { 227 result.Response = autorest.Response{Response: resp} 228 err = autorest.NewErrorWithError(err, "redis.LinkedServerClient", "Get", resp, "Failure sending request") 229 return 230 } 231 232 result, err = client.GetResponder(resp) 233 if err != nil { 234 err = autorest.NewErrorWithError(err, "redis.LinkedServerClient", "Get", resp, "Failure responding to request") 235 return 236 } 237 238 return 239} 240 241// GetPreparer prepares the Get request. 242func (client LinkedServerClient) GetPreparer(ctx context.Context, resourceGroupName string, name string, linkedServerName string) (*http.Request, error) { 243 pathParameters := map[string]interface{}{ 244 "linkedServerName": autorest.Encode("path", linkedServerName), 245 "name": autorest.Encode("path", name), 246 "resourceGroupName": autorest.Encode("path", resourceGroupName), 247 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 248 } 249 250 const APIVersion = "2020-06-01" 251 queryParameters := map[string]interface{}{ 252 "api-version": APIVersion, 253 } 254 255 preparer := autorest.CreatePreparer( 256 autorest.AsGet(), 257 autorest.WithBaseURL(client.BaseURI), 258 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/redis/{name}/linkedServers/{linkedServerName}", pathParameters), 259 autorest.WithQueryParameters(queryParameters)) 260 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 261} 262 263// GetSender sends the Get request. The method will close the 264// http.Response Body if it receives an error. 265func (client LinkedServerClient) GetSender(req *http.Request) (*http.Response, error) { 266 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 267} 268 269// GetResponder handles the response to the Get request. The method always 270// closes the http.Response Body. 271func (client LinkedServerClient) GetResponder(resp *http.Response) (result LinkedServerWithProperties, err error) { 272 err = autorest.Respond( 273 resp, 274 azure.WithErrorUnlessStatusCode(http.StatusOK), 275 autorest.ByUnmarshallingJSON(&result), 276 autorest.ByClosing()) 277 result.Response = autorest.Response{Response: resp} 278 return 279} 280 281// List gets the list of linked servers associated with this redis cache (requires Premium SKU). 282// Parameters: 283// resourceGroupName - the name of the resource group. 284// name - the name of the redis cache. 285func (client LinkedServerClient) List(ctx context.Context, resourceGroupName string, name string) (result LinkedServerWithPropertiesListPage, err error) { 286 if tracing.IsEnabled() { 287 ctx = tracing.StartSpan(ctx, fqdn+"/LinkedServerClient.List") 288 defer func() { 289 sc := -1 290 if result.lswpl.Response.Response != nil { 291 sc = result.lswpl.Response.Response.StatusCode 292 } 293 tracing.EndSpan(ctx, sc, err) 294 }() 295 } 296 result.fn = client.listNextResults 297 req, err := client.ListPreparer(ctx, resourceGroupName, name) 298 if err != nil { 299 err = autorest.NewErrorWithError(err, "redis.LinkedServerClient", "List", nil, "Failure preparing request") 300 return 301 } 302 303 resp, err := client.ListSender(req) 304 if err != nil { 305 result.lswpl.Response = autorest.Response{Response: resp} 306 err = autorest.NewErrorWithError(err, "redis.LinkedServerClient", "List", resp, "Failure sending request") 307 return 308 } 309 310 result.lswpl, err = client.ListResponder(resp) 311 if err != nil { 312 err = autorest.NewErrorWithError(err, "redis.LinkedServerClient", "List", resp, "Failure responding to request") 313 return 314 } 315 if result.lswpl.hasNextLink() && result.lswpl.IsEmpty() { 316 err = result.NextWithContext(ctx) 317 return 318 } 319 320 return 321} 322 323// ListPreparer prepares the List request. 324func (client LinkedServerClient) ListPreparer(ctx context.Context, resourceGroupName string, name string) (*http.Request, error) { 325 pathParameters := map[string]interface{}{ 326 "name": autorest.Encode("path", name), 327 "resourceGroupName": autorest.Encode("path", resourceGroupName), 328 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 329 } 330 331 const APIVersion = "2020-06-01" 332 queryParameters := map[string]interface{}{ 333 "api-version": APIVersion, 334 } 335 336 preparer := autorest.CreatePreparer( 337 autorest.AsGet(), 338 autorest.WithBaseURL(client.BaseURI), 339 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/redis/{name}/linkedServers", pathParameters), 340 autorest.WithQueryParameters(queryParameters)) 341 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 342} 343 344// ListSender sends the List request. The method will close the 345// http.Response Body if it receives an error. 346func (client LinkedServerClient) ListSender(req *http.Request) (*http.Response, error) { 347 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 348} 349 350// ListResponder handles the response to the List request. The method always 351// closes the http.Response Body. 352func (client LinkedServerClient) ListResponder(resp *http.Response) (result LinkedServerWithPropertiesList, err error) { 353 err = autorest.Respond( 354 resp, 355 azure.WithErrorUnlessStatusCode(http.StatusOK), 356 autorest.ByUnmarshallingJSON(&result), 357 autorest.ByClosing()) 358 result.Response = autorest.Response{Response: resp} 359 return 360} 361 362// listNextResults retrieves the next set of results, if any. 363func (client LinkedServerClient) listNextResults(ctx context.Context, lastResults LinkedServerWithPropertiesList) (result LinkedServerWithPropertiesList, err error) { 364 req, err := lastResults.linkedServerWithPropertiesListPreparer(ctx) 365 if err != nil { 366 return result, autorest.NewErrorWithError(err, "redis.LinkedServerClient", "listNextResults", nil, "Failure preparing next results request") 367 } 368 if req == nil { 369 return 370 } 371 resp, err := client.ListSender(req) 372 if err != nil { 373 result.Response = autorest.Response{Response: resp} 374 return result, autorest.NewErrorWithError(err, "redis.LinkedServerClient", "listNextResults", resp, "Failure sending next results request") 375 } 376 result, err = client.ListResponder(resp) 377 if err != nil { 378 err = autorest.NewErrorWithError(err, "redis.LinkedServerClient", "listNextResults", resp, "Failure responding to next results request") 379 } 380 return 381} 382 383// ListComplete enumerates all values, automatically crossing page boundaries as required. 384func (client LinkedServerClient) ListComplete(ctx context.Context, resourceGroupName string, name string) (result LinkedServerWithPropertiesListIterator, err error) { 385 if tracing.IsEnabled() { 386 ctx = tracing.StartSpan(ctx, fqdn+"/LinkedServerClient.List") 387 defer func() { 388 sc := -1 389 if result.Response().Response.Response != nil { 390 sc = result.page.Response().Response.Response.StatusCode 391 } 392 tracing.EndSpan(ctx, sc, err) 393 }() 394 } 395 result.page, err = client.List(ctx, resourceGroupName, name) 396 return 397} 398