...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2021-04-01-preview/documentdb/client.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2021-04-01-preview/documentdb

     1  // Deprecated: Please note, this package has been deprecated. A replacement package is available [github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos). We strongly encourage you to upgrade to continue receiving updates. See [Migration Guide](https://aka.ms/azsdk/golang/t2/migration) for guidance on upgrading. Refer to our [deprecation policy](https://azure.github.io/azure-sdk/policies_support.html) for more details.
     2  //
     3  // Package documentdb implements the Azure ARM Documentdb service API version 2021-04-01-preview.
     4  //
     5  //
     6  package documentdb
     7  
     8  // Copyright (c) Microsoft Corporation. All rights reserved.
     9  // Licensed under the MIT License. See License.txt in the project root for license information.
    10  //
    11  // Code generated by Microsoft (R) AutoRest Code Generator.
    12  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
    13  
    14  import (
    15  	"context"
    16  	"github.com/Azure/go-autorest/autorest"
    17  	"github.com/Azure/go-autorest/autorest/azure"
    18  	"github.com/Azure/go-autorest/autorest/validation"
    19  	"github.com/Azure/go-autorest/tracing"
    20  	"net/http"
    21  )
    22  
    23  const (
    24  	// DefaultBaseURI is the default URI used for the service Documentdb
    25  	DefaultBaseURI = "https://management.azure.com"
    26  )
    27  
    28  // BaseClient is the base client for Documentdb.
    29  type BaseClient struct {
    30  	autorest.Client
    31  	BaseURI        string
    32  	SubscriptionID string
    33  }
    34  
    35  // New creates an instance of the BaseClient client.
    36  func New(subscriptionID string) BaseClient {
    37  	return NewWithBaseURI(DefaultBaseURI, subscriptionID)
    38  }
    39  
    40  // NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint.  Use this when interacting with
    41  // an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    42  func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient {
    43  	return BaseClient{
    44  		Client:         autorest.NewClientWithUserAgent(UserAgent()),
    45  		BaseURI:        baseURI,
    46  		SubscriptionID: subscriptionID,
    47  	}
    48  }
    49  
    50  // LocationGet get the properties of an existing Cosmos DB location
    51  // Parameters:
    52  // location - cosmos DB region, with spaces between words and each word capitalized.
    53  func (client BaseClient) LocationGet(ctx context.Context, location string) (result LocationGetResult, err error) {
    54  	if tracing.IsEnabled() {
    55  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.LocationGet")
    56  		defer func() {
    57  			sc := -1
    58  			if result.Response.Response != nil {
    59  				sc = result.Response.Response.StatusCode
    60  			}
    61  			tracing.EndSpan(ctx, sc, err)
    62  		}()
    63  	}
    64  	if err := validation.Validate([]validation.Validation{
    65  		{TargetValue: client.SubscriptionID,
    66  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    67  		return result, validation.NewError("documentdb.BaseClient", "LocationGet", err.Error())
    68  	}
    69  
    70  	req, err := client.LocationGetPreparer(ctx, location)
    71  	if err != nil {
    72  		err = autorest.NewErrorWithError(err, "documentdb.BaseClient", "LocationGet", nil, "Failure preparing request")
    73  		return
    74  	}
    75  
    76  	resp, err := client.LocationGetSender(req)
    77  	if err != nil {
    78  		result.Response = autorest.Response{Response: resp}
    79  		err = autorest.NewErrorWithError(err, "documentdb.BaseClient", "LocationGet", resp, "Failure sending request")
    80  		return
    81  	}
    82  
    83  	result, err = client.LocationGetResponder(resp)
    84  	if err != nil {
    85  		err = autorest.NewErrorWithError(err, "documentdb.BaseClient", "LocationGet", resp, "Failure responding to request")
    86  		return
    87  	}
    88  
    89  	return
    90  }
    91  
    92  // LocationGetPreparer prepares the LocationGet request.
    93  func (client BaseClient) LocationGetPreparer(ctx context.Context, location string) (*http.Request, error) {
    94  	pathParameters := map[string]interface{}{
    95  		"location":       autorest.Encode("path", location),
    96  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    97  	}
    98  
    99  	const APIVersion = "2021-04-01-preview"
   100  	queryParameters := map[string]interface{}{
   101  		"api-version": APIVersion,
   102  	}
   103  
   104  	preparer := autorest.CreatePreparer(
   105  		autorest.AsGet(),
   106  		autorest.WithBaseURL(client.BaseURI),
   107  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}", pathParameters),
   108  		autorest.WithQueryParameters(queryParameters))
   109  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   110  }
   111  
   112  // LocationGetSender sends the LocationGet request. The method will close the
   113  // http.Response Body if it receives an error.
   114  func (client BaseClient) LocationGetSender(req *http.Request) (*http.Response, error) {
   115  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   116  }
   117  
   118  // LocationGetResponder handles the response to the LocationGet request. The method always
   119  // closes the http.Response Body.
   120  func (client BaseClient) LocationGetResponder(resp *http.Response) (result LocationGetResult, err error) {
   121  	err = autorest.Respond(
   122  		resp,
   123  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   124  		autorest.ByUnmarshallingJSON(&result),
   125  		autorest.ByClosing())
   126  	result.Response = autorest.Response{Response: resp}
   127  	return
   128  }
   129  
   130  // LocationList list Cosmos DB locations and their properties
   131  func (client BaseClient) LocationList(ctx context.Context) (result LocationListResult, err error) {
   132  	if tracing.IsEnabled() {
   133  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.LocationList")
   134  		defer func() {
   135  			sc := -1
   136  			if result.Response.Response != nil {
   137  				sc = result.Response.Response.StatusCode
   138  			}
   139  			tracing.EndSpan(ctx, sc, err)
   140  		}()
   141  	}
   142  	if err := validation.Validate([]validation.Validation{
   143  		{TargetValue: client.SubscriptionID,
   144  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   145  		return result, validation.NewError("documentdb.BaseClient", "LocationList", err.Error())
   146  	}
   147  
   148  	req, err := client.LocationListPreparer(ctx)
   149  	if err != nil {
   150  		err = autorest.NewErrorWithError(err, "documentdb.BaseClient", "LocationList", nil, "Failure preparing request")
   151  		return
   152  	}
   153  
   154  	resp, err := client.LocationListSender(req)
   155  	if err != nil {
   156  		result.Response = autorest.Response{Response: resp}
   157  		err = autorest.NewErrorWithError(err, "documentdb.BaseClient", "LocationList", resp, "Failure sending request")
   158  		return
   159  	}
   160  
   161  	result, err = client.LocationListResponder(resp)
   162  	if err != nil {
   163  		err = autorest.NewErrorWithError(err, "documentdb.BaseClient", "LocationList", resp, "Failure responding to request")
   164  		return
   165  	}
   166  
   167  	return
   168  }
   169  
   170  // LocationListPreparer prepares the LocationList request.
   171  func (client BaseClient) LocationListPreparer(ctx context.Context) (*http.Request, error) {
   172  	pathParameters := map[string]interface{}{
   173  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   174  	}
   175  
   176  	const APIVersion = "2021-04-01-preview"
   177  	queryParameters := map[string]interface{}{
   178  		"api-version": APIVersion,
   179  	}
   180  
   181  	preparer := autorest.CreatePreparer(
   182  		autorest.AsGet(),
   183  		autorest.WithBaseURL(client.BaseURI),
   184  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations", pathParameters),
   185  		autorest.WithQueryParameters(queryParameters))
   186  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   187  }
   188  
   189  // LocationListSender sends the LocationList request. The method will close the
   190  // http.Response Body if it receives an error.
   191  func (client BaseClient) LocationListSender(req *http.Request) (*http.Response, error) {
   192  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   193  }
   194  
   195  // LocationListResponder handles the response to the LocationList request. The method always
   196  // closes the http.Response Body.
   197  func (client BaseClient) LocationListResponder(resp *http.Response) (result LocationListResult, err error) {
   198  	err = autorest.Respond(
   199  		resp,
   200  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   201  		autorest.ByUnmarshallingJSON(&result),
   202  		autorest.ByClosing())
   203  	result.Response = autorest.Response{Response: resp}
   204  	return
   205  }
   206  

View as plain text