...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/appinsights/mgmt/2022-02-01-preview/insights/livetoken.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/appinsights/mgmt/2022-02-01-preview/insights

     1  package insights
     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  // LiveTokenClient is the composite Swagger for Application Insights Management Client
    18  type LiveTokenClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewLiveTokenClient creates an instance of the LiveTokenClient client.
    23  func NewLiveTokenClient(subscriptionID string) LiveTokenClient {
    24  	return NewLiveTokenClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewLiveTokenClientWithBaseURI creates an instance of the LiveTokenClient 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 NewLiveTokenClientWithBaseURI(baseURI string, subscriptionID string) LiveTokenClient {
    30  	return LiveTokenClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // Get **Gets an access token for live metrics stream data.**
    34  // Parameters:
    35  // resourceURI - the identifier of the resource.
    36  func (client LiveTokenClient) Get(ctx context.Context, resourceURI string) (result LiveTokenResponse, err error) {
    37  	if tracing.IsEnabled() {
    38  		ctx = tracing.StartSpan(ctx, fqdn+"/LiveTokenClient.Get")
    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.GetPreparer(ctx, resourceURI)
    48  	if err != nil {
    49  		err = autorest.NewErrorWithError(err, "insights.LiveTokenClient", "Get", nil, "Failure preparing request")
    50  		return
    51  	}
    52  
    53  	resp, err := client.GetSender(req)
    54  	if err != nil {
    55  		result.Response = autorest.Response{Response: resp}
    56  		err = autorest.NewErrorWithError(err, "insights.LiveTokenClient", "Get", resp, "Failure sending request")
    57  		return
    58  	}
    59  
    60  	result, err = client.GetResponder(resp)
    61  	if err != nil {
    62  		err = autorest.NewErrorWithError(err, "insights.LiveTokenClient", "Get", resp, "Failure responding to request")
    63  		return
    64  	}
    65  
    66  	return
    67  }
    68  
    69  // GetPreparer prepares the Get request.
    70  func (client LiveTokenClient) GetPreparer(ctx context.Context, resourceURI string) (*http.Request, error) {
    71  	pathParameters := map[string]interface{}{
    72  		"resourceUri": resourceURI,
    73  	}
    74  
    75  	const APIVersion = "2021-10-14"
    76  	queryParameters := map[string]interface{}{
    77  		"api-version": APIVersion,
    78  	}
    79  
    80  	preparer := autorest.CreatePreparer(
    81  		autorest.AsPost(),
    82  		autorest.WithBaseURL(client.BaseURI),
    83  		autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Insights/generatelivetoken", pathParameters),
    84  		autorest.WithQueryParameters(queryParameters))
    85  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    86  }
    87  
    88  // GetSender sends the Get request. The method will close the
    89  // http.Response Body if it receives an error.
    90  func (client LiveTokenClient) GetSender(req *http.Request) (*http.Response, error) {
    91  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    92  }
    93  
    94  // GetResponder handles the response to the Get request. The method always
    95  // closes the http.Response Body.
    96  func (client LiveTokenClient) GetResponder(resp *http.Response) (result LiveTokenResponse, err error) {
    97  	err = autorest.Respond(
    98  		resp,
    99  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   100  		autorest.ByUnmarshallingJSON(&result),
   101  		autorest.ByClosing())
   102  	result.Response = autorest.Response{Response: resp}
   103  	return
   104  }
   105  

View as plain text