...

Source file src/github.com/Azure/azure-sdk-for-go/services/mediaservices/mgmt/2021-06-01/media/liveoutputs.go

Documentation: github.com/Azure/azure-sdk-for-go/services/mediaservices/mgmt/2021-06-01/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/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // LiveOutputsClient is the client for the LiveOutputs methods of the Media service.
    19  type LiveOutputsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewLiveOutputsClient creates an instance of the LiveOutputsClient client.
    24  func NewLiveOutputsClient(subscriptionID string) LiveOutputsClient {
    25  	return NewLiveOutputsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewLiveOutputsClientWithBaseURI creates an instance of the LiveOutputsClient 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).
    30  func NewLiveOutputsClientWithBaseURI(baseURI string, subscriptionID string) LiveOutputsClient {
    31  	return LiveOutputsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // Create creates a new live output.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group within the Azure subscription.
    37  // accountName - the Media Services account name.
    38  // liveEventName - the name of the live event, maximum length is 32.
    39  // liveOutputName - the name of the live output.
    40  // parameters - live Output properties needed for creation.
    41  func (client LiveOutputsClient) Create(ctx context.Context, resourceGroupName string, accountName string, liveEventName string, liveOutputName string, parameters LiveOutput) (result LiveOutputsCreateFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/LiveOutputsClient.Create")
    44  		defer func() {
    45  			sc := -1
    46  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    47  				sc = result.FutureAPI.Response().StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	if err := validation.Validate([]validation.Validation{
    53  		{TargetValue: liveEventName,
    54  			Constraints: []validation.Constraint{{Target: "liveEventName", Name: validation.MaxLength, Rule: 32, Chain: nil},
    55  				{Target: "liveEventName", Name: validation.MinLength, Rule: 1, Chain: nil},
    56  				{Target: "liveEventName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$`, Chain: nil}}},
    57  		{TargetValue: liveOutputName,
    58  			Constraints: []validation.Constraint{{Target: "liveOutputName", Name: validation.MaxLength, Rule: 256, Chain: nil},
    59  				{Target: "liveOutputName", Name: validation.MinLength, Rule: 1, Chain: nil},
    60  				{Target: "liveOutputName", Name: validation.Pattern, Rule: `^([a-zA-Z0-9])+(-*[a-zA-Z0-9])*$`, Chain: nil}}},
    61  		{TargetValue: parameters,
    62  			Constraints: []validation.Constraint{{Target: "parameters.LiveOutputProperties", Name: validation.Null, Rule: false,
    63  				Chain: []validation.Constraint{{Target: "parameters.LiveOutputProperties.AssetName", Name: validation.Null, Rule: true, Chain: nil},
    64  					{Target: "parameters.LiveOutputProperties.ArchiveWindowLength", Name: validation.Null, Rule: true, Chain: nil},
    65  				}}}}}); err != nil {
    66  		return result, validation.NewError("media.LiveOutputsClient", "Create", err.Error())
    67  	}
    68  
    69  	req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, liveEventName, liveOutputName, parameters)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "media.LiveOutputsClient", "Create", nil, "Failure preparing request")
    72  		return
    73  	}
    74  
    75  	result, err = client.CreateSender(req)
    76  	if err != nil {
    77  		err = autorest.NewErrorWithError(err, "media.LiveOutputsClient", "Create", result.Response(), "Failure sending request")
    78  		return
    79  	}
    80  
    81  	return
    82  }
    83  
    84  // CreatePreparer prepares the Create request.
    85  func (client LiveOutputsClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, liveEventName string, liveOutputName string, parameters LiveOutput) (*http.Request, error) {
    86  	pathParameters := map[string]interface{}{
    87  		"accountName":       autorest.Encode("path", accountName),
    88  		"liveEventName":     autorest.Encode("path", liveEventName),
    89  		"liveOutputName":    autorest.Encode("path", liveOutputName),
    90  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    91  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    92  	}
    93  
    94  	const APIVersion = "2021-06-01"
    95  	queryParameters := map[string]interface{}{
    96  		"api-version": APIVersion,
    97  	}
    98  
    99  	parameters.SystemData = nil
   100  	preparer := autorest.CreatePreparer(
   101  		autorest.AsContentType("application/json; charset=utf-8"),
   102  		autorest.AsPut(),
   103  		autorest.WithBaseURL(client.BaseURI),
   104  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/liveEvents/{liveEventName}/liveOutputs/{liveOutputName}", pathParameters),
   105  		autorest.WithJSON(parameters),
   106  		autorest.WithQueryParameters(queryParameters))
   107  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   108  }
   109  
   110  // CreateSender sends the Create request. The method will close the
   111  // http.Response Body if it receives an error.
   112  func (client LiveOutputsClient) CreateSender(req *http.Request) (future LiveOutputsCreateFuture, err error) {
   113  	var resp *http.Response
   114  	future.FutureAPI = &azure.Future{}
   115  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   116  	if err != nil {
   117  		return
   118  	}
   119  	var azf azure.Future
   120  	azf, err = azure.NewFutureFromResponse(resp)
   121  	future.FutureAPI = &azf
   122  	future.Result = future.result
   123  	return
   124  }
   125  
   126  // CreateResponder handles the response to the Create request. The method always
   127  // closes the http.Response Body.
   128  func (client LiveOutputsClient) CreateResponder(resp *http.Response) (result LiveOutput, err error) {
   129  	err = autorest.Respond(
   130  		resp,
   131  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   132  		autorest.ByUnmarshallingJSON(&result),
   133  		autorest.ByClosing())
   134  	result.Response = autorest.Response{Response: resp}
   135  	return
   136  }
   137  
   138  // Delete deletes a live output. Deleting a live output does not delete the asset the live output is writing to.
   139  // Parameters:
   140  // resourceGroupName - the name of the resource group within the Azure subscription.
   141  // accountName - the Media Services account name.
   142  // liveEventName - the name of the live event, maximum length is 32.
   143  // liveOutputName - the name of the live output.
   144  func (client LiveOutputsClient) Delete(ctx context.Context, resourceGroupName string, accountName string, liveEventName string, liveOutputName string) (result LiveOutputsDeleteFuture, err error) {
   145  	if tracing.IsEnabled() {
   146  		ctx = tracing.StartSpan(ctx, fqdn+"/LiveOutputsClient.Delete")
   147  		defer func() {
   148  			sc := -1
   149  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   150  				sc = result.FutureAPI.Response().StatusCode
   151  			}
   152  			tracing.EndSpan(ctx, sc, err)
   153  		}()
   154  	}
   155  	if err := validation.Validate([]validation.Validation{
   156  		{TargetValue: liveEventName,
   157  			Constraints: []validation.Constraint{{Target: "liveEventName", Name: validation.MaxLength, Rule: 32, Chain: nil},
   158  				{Target: "liveEventName", Name: validation.MinLength, Rule: 1, Chain: nil},
   159  				{Target: "liveEventName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$`, Chain: nil}}},
   160  		{TargetValue: liveOutputName,
   161  			Constraints: []validation.Constraint{{Target: "liveOutputName", Name: validation.MaxLength, Rule: 256, Chain: nil},
   162  				{Target: "liveOutputName", Name: validation.MinLength, Rule: 1, Chain: nil},
   163  				{Target: "liveOutputName", Name: validation.Pattern, Rule: `^([a-zA-Z0-9])+(-*[a-zA-Z0-9])*$`, Chain: nil}}}}); err != nil {
   164  		return result, validation.NewError("media.LiveOutputsClient", "Delete", err.Error())
   165  	}
   166  
   167  	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, liveEventName, liveOutputName)
   168  	if err != nil {
   169  		err = autorest.NewErrorWithError(err, "media.LiveOutputsClient", "Delete", nil, "Failure preparing request")
   170  		return
   171  	}
   172  
   173  	result, err = client.DeleteSender(req)
   174  	if err != nil {
   175  		err = autorest.NewErrorWithError(err, "media.LiveOutputsClient", "Delete", result.Response(), "Failure sending request")
   176  		return
   177  	}
   178  
   179  	return
   180  }
   181  
   182  // DeletePreparer prepares the Delete request.
   183  func (client LiveOutputsClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, liveEventName string, liveOutputName string) (*http.Request, error) {
   184  	pathParameters := map[string]interface{}{
   185  		"accountName":       autorest.Encode("path", accountName),
   186  		"liveEventName":     autorest.Encode("path", liveEventName),
   187  		"liveOutputName":    autorest.Encode("path", liveOutputName),
   188  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   189  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   190  	}
   191  
   192  	const APIVersion = "2021-06-01"
   193  	queryParameters := map[string]interface{}{
   194  		"api-version": APIVersion,
   195  	}
   196  
   197  	preparer := autorest.CreatePreparer(
   198  		autorest.AsDelete(),
   199  		autorest.WithBaseURL(client.BaseURI),
   200  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/liveEvents/{liveEventName}/liveOutputs/{liveOutputName}", pathParameters),
   201  		autorest.WithQueryParameters(queryParameters))
   202  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   203  }
   204  
   205  // DeleteSender sends the Delete request. The method will close the
   206  // http.Response Body if it receives an error.
   207  func (client LiveOutputsClient) DeleteSender(req *http.Request) (future LiveOutputsDeleteFuture, err error) {
   208  	var resp *http.Response
   209  	future.FutureAPI = &azure.Future{}
   210  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   211  	if err != nil {
   212  		return
   213  	}
   214  	var azf azure.Future
   215  	azf, err = azure.NewFutureFromResponse(resp)
   216  	future.FutureAPI = &azf
   217  	future.Result = future.result
   218  	return
   219  }
   220  
   221  // DeleteResponder handles the response to the Delete request. The method always
   222  // closes the http.Response Body.
   223  func (client LiveOutputsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   224  	err = autorest.Respond(
   225  		resp,
   226  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   227  		autorest.ByClosing())
   228  	result.Response = resp
   229  	return
   230  }
   231  
   232  // Get gets a live output.
   233  // Parameters:
   234  // resourceGroupName - the name of the resource group within the Azure subscription.
   235  // accountName - the Media Services account name.
   236  // liveEventName - the name of the live event, maximum length is 32.
   237  // liveOutputName - the name of the live output.
   238  func (client LiveOutputsClient) Get(ctx context.Context, resourceGroupName string, accountName string, liveEventName string, liveOutputName string) (result LiveOutput, err error) {
   239  	if tracing.IsEnabled() {
   240  		ctx = tracing.StartSpan(ctx, fqdn+"/LiveOutputsClient.Get")
   241  		defer func() {
   242  			sc := -1
   243  			if result.Response.Response != nil {
   244  				sc = result.Response.Response.StatusCode
   245  			}
   246  			tracing.EndSpan(ctx, sc, err)
   247  		}()
   248  	}
   249  	if err := validation.Validate([]validation.Validation{
   250  		{TargetValue: liveEventName,
   251  			Constraints: []validation.Constraint{{Target: "liveEventName", Name: validation.MaxLength, Rule: 32, Chain: nil},
   252  				{Target: "liveEventName", Name: validation.MinLength, Rule: 1, Chain: nil},
   253  				{Target: "liveEventName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$`, Chain: nil}}},
   254  		{TargetValue: liveOutputName,
   255  			Constraints: []validation.Constraint{{Target: "liveOutputName", Name: validation.MaxLength, Rule: 256, Chain: nil},
   256  				{Target: "liveOutputName", Name: validation.MinLength, Rule: 1, Chain: nil},
   257  				{Target: "liveOutputName", Name: validation.Pattern, Rule: `^([a-zA-Z0-9])+(-*[a-zA-Z0-9])*$`, Chain: nil}}}}); err != nil {
   258  		return result, validation.NewError("media.LiveOutputsClient", "Get", err.Error())
   259  	}
   260  
   261  	req, err := client.GetPreparer(ctx, resourceGroupName, accountName, liveEventName, liveOutputName)
   262  	if err != nil {
   263  		err = autorest.NewErrorWithError(err, "media.LiveOutputsClient", "Get", nil, "Failure preparing request")
   264  		return
   265  	}
   266  
   267  	resp, err := client.GetSender(req)
   268  	if err != nil {
   269  		result.Response = autorest.Response{Response: resp}
   270  		err = autorest.NewErrorWithError(err, "media.LiveOutputsClient", "Get", resp, "Failure sending request")
   271  		return
   272  	}
   273  
   274  	result, err = client.GetResponder(resp)
   275  	if err != nil {
   276  		err = autorest.NewErrorWithError(err, "media.LiveOutputsClient", "Get", resp, "Failure responding to request")
   277  		return
   278  	}
   279  
   280  	return
   281  }
   282  
   283  // GetPreparer prepares the Get request.
   284  func (client LiveOutputsClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, liveEventName string, liveOutputName string) (*http.Request, error) {
   285  	pathParameters := map[string]interface{}{
   286  		"accountName":       autorest.Encode("path", accountName),
   287  		"liveEventName":     autorest.Encode("path", liveEventName),
   288  		"liveOutputName":    autorest.Encode("path", liveOutputName),
   289  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   290  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   291  	}
   292  
   293  	const APIVersion = "2021-06-01"
   294  	queryParameters := map[string]interface{}{
   295  		"api-version": APIVersion,
   296  	}
   297  
   298  	preparer := autorest.CreatePreparer(
   299  		autorest.AsGet(),
   300  		autorest.WithBaseURL(client.BaseURI),
   301  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/liveEvents/{liveEventName}/liveOutputs/{liveOutputName}", pathParameters),
   302  		autorest.WithQueryParameters(queryParameters))
   303  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   304  }
   305  
   306  // GetSender sends the Get request. The method will close the
   307  // http.Response Body if it receives an error.
   308  func (client LiveOutputsClient) GetSender(req *http.Request) (*http.Response, error) {
   309  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   310  }
   311  
   312  // GetResponder handles the response to the Get request. The method always
   313  // closes the http.Response Body.
   314  func (client LiveOutputsClient) GetResponder(resp *http.Response) (result LiveOutput, err error) {
   315  	err = autorest.Respond(
   316  		resp,
   317  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   318  		autorest.ByUnmarshallingJSON(&result),
   319  		autorest.ByClosing())
   320  	result.Response = autorest.Response{Response: resp}
   321  	return
   322  }
   323  
   324  // List lists the live outputs of a live event.
   325  // Parameters:
   326  // resourceGroupName - the name of the resource group within the Azure subscription.
   327  // accountName - the Media Services account name.
   328  // liveEventName - the name of the live event, maximum length is 32.
   329  func (client LiveOutputsClient) List(ctx context.Context, resourceGroupName string, accountName string, liveEventName string) (result LiveOutputListResultPage, err error) {
   330  	if tracing.IsEnabled() {
   331  		ctx = tracing.StartSpan(ctx, fqdn+"/LiveOutputsClient.List")
   332  		defer func() {
   333  			sc := -1
   334  			if result.lolr.Response.Response != nil {
   335  				sc = result.lolr.Response.Response.StatusCode
   336  			}
   337  			tracing.EndSpan(ctx, sc, err)
   338  		}()
   339  	}
   340  	if err := validation.Validate([]validation.Validation{
   341  		{TargetValue: liveEventName,
   342  			Constraints: []validation.Constraint{{Target: "liveEventName", Name: validation.MaxLength, Rule: 32, Chain: nil},
   343  				{Target: "liveEventName", Name: validation.MinLength, Rule: 1, Chain: nil},
   344  				{Target: "liveEventName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$`, Chain: nil}}}}); err != nil {
   345  		return result, validation.NewError("media.LiveOutputsClient", "List", err.Error())
   346  	}
   347  
   348  	result.fn = client.listNextResults
   349  	req, err := client.ListPreparer(ctx, resourceGroupName, accountName, liveEventName)
   350  	if err != nil {
   351  		err = autorest.NewErrorWithError(err, "media.LiveOutputsClient", "List", nil, "Failure preparing request")
   352  		return
   353  	}
   354  
   355  	resp, err := client.ListSender(req)
   356  	if err != nil {
   357  		result.lolr.Response = autorest.Response{Response: resp}
   358  		err = autorest.NewErrorWithError(err, "media.LiveOutputsClient", "List", resp, "Failure sending request")
   359  		return
   360  	}
   361  
   362  	result.lolr, err = client.ListResponder(resp)
   363  	if err != nil {
   364  		err = autorest.NewErrorWithError(err, "media.LiveOutputsClient", "List", resp, "Failure responding to request")
   365  		return
   366  	}
   367  	if result.lolr.hasNextLink() && result.lolr.IsEmpty() {
   368  		err = result.NextWithContext(ctx)
   369  		return
   370  	}
   371  
   372  	return
   373  }
   374  
   375  // ListPreparer prepares the List request.
   376  func (client LiveOutputsClient) ListPreparer(ctx context.Context, resourceGroupName string, accountName string, liveEventName string) (*http.Request, error) {
   377  	pathParameters := map[string]interface{}{
   378  		"accountName":       autorest.Encode("path", accountName),
   379  		"liveEventName":     autorest.Encode("path", liveEventName),
   380  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   381  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   382  	}
   383  
   384  	const APIVersion = "2021-06-01"
   385  	queryParameters := map[string]interface{}{
   386  		"api-version": APIVersion,
   387  	}
   388  
   389  	preparer := autorest.CreatePreparer(
   390  		autorest.AsGet(),
   391  		autorest.WithBaseURL(client.BaseURI),
   392  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/liveEvents/{liveEventName}/liveOutputs", pathParameters),
   393  		autorest.WithQueryParameters(queryParameters))
   394  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   395  }
   396  
   397  // ListSender sends the List request. The method will close the
   398  // http.Response Body if it receives an error.
   399  func (client LiveOutputsClient) ListSender(req *http.Request) (*http.Response, error) {
   400  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   401  }
   402  
   403  // ListResponder handles the response to the List request. The method always
   404  // closes the http.Response Body.
   405  func (client LiveOutputsClient) ListResponder(resp *http.Response) (result LiveOutputListResult, err error) {
   406  	err = autorest.Respond(
   407  		resp,
   408  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   409  		autorest.ByUnmarshallingJSON(&result),
   410  		autorest.ByClosing())
   411  	result.Response = autorest.Response{Response: resp}
   412  	return
   413  }
   414  
   415  // listNextResults retrieves the next set of results, if any.
   416  func (client LiveOutputsClient) listNextResults(ctx context.Context, lastResults LiveOutputListResult) (result LiveOutputListResult, err error) {
   417  	req, err := lastResults.liveOutputListResultPreparer(ctx)
   418  	if err != nil {
   419  		return result, autorest.NewErrorWithError(err, "media.LiveOutputsClient", "listNextResults", nil, "Failure preparing next results request")
   420  	}
   421  	if req == nil {
   422  		return
   423  	}
   424  	resp, err := client.ListSender(req)
   425  	if err != nil {
   426  		result.Response = autorest.Response{Response: resp}
   427  		return result, autorest.NewErrorWithError(err, "media.LiveOutputsClient", "listNextResults", resp, "Failure sending next results request")
   428  	}
   429  	result, err = client.ListResponder(resp)
   430  	if err != nil {
   431  		err = autorest.NewErrorWithError(err, "media.LiveOutputsClient", "listNextResults", resp, "Failure responding to next results request")
   432  	}
   433  	return
   434  }
   435  
   436  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   437  func (client LiveOutputsClient) ListComplete(ctx context.Context, resourceGroupName string, accountName string, liveEventName string) (result LiveOutputListResultIterator, err error) {
   438  	if tracing.IsEnabled() {
   439  		ctx = tracing.StartSpan(ctx, fqdn+"/LiveOutputsClient.List")
   440  		defer func() {
   441  			sc := -1
   442  			if result.Response().Response.Response != nil {
   443  				sc = result.page.Response().Response.Response.StatusCode
   444  			}
   445  			tracing.EndSpan(ctx, sc, err)
   446  		}()
   447  	}
   448  	result.page, err = client.List(ctx, resourceGroupName, accountName, liveEventName)
   449  	return
   450  }
   451  

View as plain text