1package postgresql 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// LocationBasedPerformanceTierClient is the the Microsoft Azure management API provides create, read, update, and 30// delete functionality for Azure PostgreSQL resources including servers, databases, firewall rules, VNET rules, 31// security alert policies, log files and configurations with new business model. 32type LocationBasedPerformanceTierClient struct { 33 BaseClient 34} 35 36// NewLocationBasedPerformanceTierClient creates an instance of the LocationBasedPerformanceTierClient client. 37func NewLocationBasedPerformanceTierClient(subscriptionID string) LocationBasedPerformanceTierClient { 38 return NewLocationBasedPerformanceTierClientWithBaseURI(DefaultBaseURI, subscriptionID) 39} 40 41// NewLocationBasedPerformanceTierClientWithBaseURI creates an instance of the LocationBasedPerformanceTierClient 42// client using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI 43// (sovereign clouds, Azure stack). 44func NewLocationBasedPerformanceTierClientWithBaseURI(baseURI string, subscriptionID string) LocationBasedPerformanceTierClient { 45 return LocationBasedPerformanceTierClient{NewWithBaseURI(baseURI, subscriptionID)} 46} 47 48// List list all the performance tiers at specified location in a given subscription. 49// Parameters: 50// locationName - the name of the location. 51func (client LocationBasedPerformanceTierClient) List(ctx context.Context, locationName string) (result PerformanceTierListResult, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/LocationBasedPerformanceTierClient.List") 54 defer func() { 55 sc := -1 56 if result.Response.Response != nil { 57 sc = result.Response.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 if err := validation.Validate([]validation.Validation{ 63 {TargetValue: client.SubscriptionID, 64 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 65 return result, validation.NewError("postgresql.LocationBasedPerformanceTierClient", "List", err.Error()) 66 } 67 68 req, err := client.ListPreparer(ctx, locationName) 69 if err != nil { 70 err = autorest.NewErrorWithError(err, "postgresql.LocationBasedPerformanceTierClient", "List", nil, "Failure preparing request") 71 return 72 } 73 74 resp, err := client.ListSender(req) 75 if err != nil { 76 result.Response = autorest.Response{Response: resp} 77 err = autorest.NewErrorWithError(err, "postgresql.LocationBasedPerformanceTierClient", "List", resp, "Failure sending request") 78 return 79 } 80 81 result, err = client.ListResponder(resp) 82 if err != nil { 83 err = autorest.NewErrorWithError(err, "postgresql.LocationBasedPerformanceTierClient", "List", resp, "Failure responding to request") 84 } 85 86 return 87} 88 89// ListPreparer prepares the List request. 90func (client LocationBasedPerformanceTierClient) ListPreparer(ctx context.Context, locationName string) (*http.Request, error) { 91 pathParameters := map[string]interface{}{ 92 "locationName": autorest.Encode("path", locationName), 93 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 94 } 95 96 const APIVersion = "2017-12-01" 97 queryParameters := map[string]interface{}{ 98 "api-version": APIVersion, 99 } 100 101 preparer := autorest.CreatePreparer( 102 autorest.AsGet(), 103 autorest.WithBaseURL(client.BaseURI), 104 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DBforPostgreSQL/locations/{locationName}/performanceTiers", pathParameters), 105 autorest.WithQueryParameters(queryParameters)) 106 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 107} 108 109// ListSender sends the List request. The method will close the 110// http.Response Body if it receives an error. 111func (client LocationBasedPerformanceTierClient) ListSender(req *http.Request) (*http.Response, error) { 112 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 113} 114 115// ListResponder handles the response to the List request. The method always 116// closes the http.Response Body. 117func (client LocationBasedPerformanceTierClient) ListResponder(resp *http.Response) (result PerformanceTierListResult, err error) { 118 err = autorest.Respond( 119 resp, 120 client.ByInspecting(), 121 azure.WithErrorUnlessStatusCode(http.StatusOK), 122 autorest.ByUnmarshallingJSON(&result), 123 autorest.ByClosing()) 124 result.Response = autorest.Response{Response: resp} 125 return 126} 127