...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/mediaservices/mgmt/2018-06-01-preview/media/locations.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/mediaservices/mgmt/2018-06-01-preview/media

     1  package media
     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  
     9  import (
    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  // LocationsClient is the client for the Locations methods of the Media service.
    18  type LocationsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewLocationsClient creates an instance of the LocationsClient client.
    23  func NewLocationsClient(subscriptionID string) LocationsClient {
    24  	return NewLocationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewLocationsClientWithBaseURI creates an instance of the LocationsClient client using a custom endpoint.  Use this
    28  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewLocationsClientWithBaseURI(baseURI string, subscriptionID string) LocationsClient {
    30  	return LocationsClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // CheckNameAvailability checks whether the Media Service resource name is available.
    34  // Parameters:
    35  // parameters - the request parameters
    36  func (client LocationsClient) CheckNameAvailability(ctx context.Context, locationName string, parameters CheckNameAvailabilityInput) (result EntityNameAvailabilityCheckOutput, err error) {
    37  	if tracing.IsEnabled() {
    38  		ctx = tracing.StartSpan(ctx, fqdn+"/LocationsClient.CheckNameAvailability")
    39  		defer func() {
    40  			sc := -1
    41  			if result.Response.Response != nil {
    42  				sc = result.Response.Response.StatusCode
    43  			}
    44  			tracing.EndSpan(ctx, sc, err)
    45  		}()
    46  	}
    47  	req, err := client.CheckNameAvailabilityPreparer(ctx, locationName, parameters)
    48  	if err != nil {
    49  		err = autorest.NewErrorWithError(err, "media.LocationsClient", "CheckNameAvailability", nil, "Failure preparing request")
    50  		return
    51  	}
    52  
    53  	resp, err := client.CheckNameAvailabilitySender(req)
    54  	if err != nil {
    55  		result.Response = autorest.Response{Response: resp}
    56  		err = autorest.NewErrorWithError(err, "media.LocationsClient", "CheckNameAvailability", resp, "Failure sending request")
    57  		return
    58  	}
    59  
    60  	result, err = client.CheckNameAvailabilityResponder(resp)
    61  	if err != nil {
    62  		err = autorest.NewErrorWithError(err, "media.LocationsClient", "CheckNameAvailability", resp, "Failure responding to request")
    63  		return
    64  	}
    65  
    66  	return
    67  }
    68  
    69  // CheckNameAvailabilityPreparer prepares the CheckNameAvailability request.
    70  func (client LocationsClient) CheckNameAvailabilityPreparer(ctx context.Context, locationName string, parameters CheckNameAvailabilityInput) (*http.Request, error) {
    71  	pathParameters := map[string]interface{}{
    72  		"locationName":   autorest.Encode("path", locationName),
    73  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    74  	}
    75  
    76  	const APIVersion = "2018-06-01-preview"
    77  	queryParameters := map[string]interface{}{
    78  		"api-version": APIVersion,
    79  	}
    80  
    81  	preparer := autorest.CreatePreparer(
    82  		autorest.AsContentType("application/json; charset=utf-8"),
    83  		autorest.AsPost(),
    84  		autorest.WithBaseURL(client.BaseURI),
    85  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Media/locations/{locationName}/checkNameAvailability", pathParameters),
    86  		autorest.WithJSON(parameters),
    87  		autorest.WithQueryParameters(queryParameters))
    88  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    89  }
    90  
    91  // CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the
    92  // http.Response Body if it receives an error.
    93  func (client LocationsClient) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) {
    94  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
    95  }
    96  
    97  // CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always
    98  // closes the http.Response Body.
    99  func (client LocationsClient) CheckNameAvailabilityResponder(resp *http.Response) (result EntityNameAvailabilityCheckOutput, err error) {
   100  	err = autorest.Respond(
   101  		resp,
   102  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   103  		autorest.ByUnmarshallingJSON(&result),
   104  		autorest.ByClosing())
   105  	result.Response = autorest.Response{Response: resp}
   106  	return
   107  }
   108  

View as plain text