...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2022-06-01-preview/insights/metricdefinitions.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2022-06-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/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // MetricDefinitionsClient is the monitor Management Client
    19  type MetricDefinitionsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewMetricDefinitionsClient creates an instance of the MetricDefinitionsClient client.
    24  func NewMetricDefinitionsClient(subscriptionID string) MetricDefinitionsClient {
    25  	return NewMetricDefinitionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewMetricDefinitionsClientWithBaseURI creates an instance of the MetricDefinitionsClient client using a custom
    29  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    30  // stack).
    31  func NewMetricDefinitionsClientWithBaseURI(baseURI string, subscriptionID string) MetricDefinitionsClient {
    32  	return MetricDefinitionsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // List lists the metric definitions for the resource.
    36  // Parameters:
    37  // resourceURI - the identifier of the resource.
    38  // metricnamespace - metric namespace to query metric definitions for.
    39  func (client MetricDefinitionsClient) List(ctx context.Context, resourceURI string, metricnamespace string) (result MetricDefinitionCollection, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/MetricDefinitionsClient.List")
    42  		defer func() {
    43  			sc := -1
    44  			if result.Response.Response != nil {
    45  				sc = result.Response.Response.StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	if err := validation.Validate([]validation.Validation{
    51  		{TargetValue: resourceURI,
    52  			Constraints: []validation.Constraint{{Target: "resourceURI", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    53  		return result, validation.NewError("insights.MetricDefinitionsClient", "List", err.Error())
    54  	}
    55  
    56  	req, err := client.ListPreparer(ctx, resourceURI, metricnamespace)
    57  	if err != nil {
    58  		err = autorest.NewErrorWithError(err, "insights.MetricDefinitionsClient", "List", nil, "Failure preparing request")
    59  		return
    60  	}
    61  
    62  	resp, err := client.ListSender(req)
    63  	if err != nil {
    64  		result.Response = autorest.Response{Response: resp}
    65  		err = autorest.NewErrorWithError(err, "insights.MetricDefinitionsClient", "List", resp, "Failure sending request")
    66  		return
    67  	}
    68  
    69  	result, err = client.ListResponder(resp)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "insights.MetricDefinitionsClient", "List", resp, "Failure responding to request")
    72  		return
    73  	}
    74  
    75  	return
    76  }
    77  
    78  // ListPreparer prepares the List request.
    79  func (client MetricDefinitionsClient) ListPreparer(ctx context.Context, resourceURI string, metricnamespace string) (*http.Request, error) {
    80  	pathParameters := map[string]interface{}{
    81  		"resourceUri": resourceURI,
    82  	}
    83  
    84  	const APIVersion = "2018-01-01"
    85  	queryParameters := map[string]interface{}{
    86  		"api-version": APIVersion,
    87  	}
    88  	if len(metricnamespace) > 0 {
    89  		queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
    90  	}
    91  
    92  	preparer := autorest.CreatePreparer(
    93  		autorest.AsGet(),
    94  		autorest.WithBaseURL(client.BaseURI),
    95  		autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Insights/metricDefinitions", pathParameters),
    96  		autorest.WithQueryParameters(queryParameters))
    97  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    98  }
    99  
   100  // ListSender sends the List request. The method will close the
   101  // http.Response Body if it receives an error.
   102  func (client MetricDefinitionsClient) ListSender(req *http.Request) (*http.Response, error) {
   103  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   104  }
   105  
   106  // ListResponder handles the response to the List request. The method always
   107  // closes the http.Response Body.
   108  func (client MetricDefinitionsClient) ListResponder(resp *http.Response) (result MetricDefinitionCollection, err error) {
   109  	err = autorest.Respond(
   110  		resp,
   111  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   112  		autorest.ByUnmarshallingJSON(&result),
   113  		autorest.ByClosing())
   114  	result.Response = autorest.Response{Response: resp}
   115  	return
   116  }
   117  

View as plain text