...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-05-01-preview/metrics/definitions.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-05-01-preview/metrics

     1  package metrics
     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  // DefinitionsClient is the monitor Management Client
    19  type DefinitionsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewDefinitionsClient creates an instance of the DefinitionsClient client.
    24  func NewDefinitionsClient(subscriptionID string) DefinitionsClient {
    25  	return NewDefinitionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewDefinitionsClientWithBaseURI creates an instance of the DefinitionsClient 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 NewDefinitionsClientWithBaseURI(baseURI string, subscriptionID string) DefinitionsClient {
    31  	return DefinitionsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // List lists the metric definitions for the resource.
    35  // Parameters:
    36  // resourceURI - the identifier of the resource.
    37  // metricnamespace - metric namespace where the metrics you want reside.
    38  func (client DefinitionsClient) List(ctx context.Context, resourceURI string, metricnamespace string) (result DefinitionCollection, err error) {
    39  	if tracing.IsEnabled() {
    40  		ctx = tracing.StartSpan(ctx, fqdn+"/DefinitionsClient.List")
    41  		defer func() {
    42  			sc := -1
    43  			if result.Response.Response != nil {
    44  				sc = result.Response.Response.StatusCode
    45  			}
    46  			tracing.EndSpan(ctx, sc, err)
    47  		}()
    48  	}
    49  	req, err := client.ListPreparer(ctx, resourceURI, metricnamespace)
    50  	if err != nil {
    51  		err = autorest.NewErrorWithError(err, "metrics.DefinitionsClient", "List", nil, "Failure preparing request")
    52  		return
    53  	}
    54  
    55  	resp, err := client.ListSender(req)
    56  	if err != nil {
    57  		result.Response = autorest.Response{Response: resp}
    58  		err = autorest.NewErrorWithError(err, "metrics.DefinitionsClient", "List", resp, "Failure sending request")
    59  		return
    60  	}
    61  
    62  	result, err = client.ListResponder(resp)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "metrics.DefinitionsClient", "List", resp, "Failure responding to request")
    65  		return
    66  	}
    67  
    68  	return
    69  }
    70  
    71  // ListPreparer prepares the List request.
    72  func (client DefinitionsClient) ListPreparer(ctx context.Context, resourceURI string, metricnamespace string) (*http.Request, error) {
    73  	pathParameters := map[string]interface{}{
    74  		"resourceUri": resourceURI,
    75  	}
    76  
    77  	const APIVersion = "2021-05-01"
    78  	queryParameters := map[string]interface{}{
    79  		"api-version": APIVersion,
    80  	}
    81  	if len(metricnamespace) > 0 {
    82  		queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
    83  	}
    84  
    85  	preparer := autorest.CreatePreparer(
    86  		autorest.AsGet(),
    87  		autorest.WithBaseURL(client.BaseURI),
    88  		autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Insights/metricDefinitions", pathParameters),
    89  		autorest.WithQueryParameters(queryParameters))
    90  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    91  }
    92  
    93  // ListSender sends the List request. The method will close the
    94  // http.Response Body if it receives an error.
    95  func (client DefinitionsClient) ListSender(req *http.Request) (*http.Response, error) {
    96  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    97  }
    98  
    99  // ListResponder handles the response to the List request. The method always
   100  // closes the http.Response Body.
   101  func (client DefinitionsClient) ListResponder(resp *http.Response) (result DefinitionCollection, err error) {
   102  	err = autorest.Respond(
   103  		resp,
   104  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   105  		autorest.ByUnmarshallingJSON(&result),
   106  		autorest.ByClosing())
   107  	result.Response = autorest.Response{Response: resp}
   108  	return
   109  }
   110  
   111  // ListAtSubscriptionScope lists the metric definitions for the subscription.
   112  // Parameters:
   113  // region - the region where the metrics you want reside.
   114  // metricnamespace - metric namespace where the metrics you want reside.
   115  func (client DefinitionsClient) ListAtSubscriptionScope(ctx context.Context, region string, metricnamespace string) (result SubscriptionScopeMetricDefinitionCollection, err error) {
   116  	if tracing.IsEnabled() {
   117  		ctx = tracing.StartSpan(ctx, fqdn+"/DefinitionsClient.ListAtSubscriptionScope")
   118  		defer func() {
   119  			sc := -1
   120  			if result.Response.Response != nil {
   121  				sc = result.Response.Response.StatusCode
   122  			}
   123  			tracing.EndSpan(ctx, sc, err)
   124  		}()
   125  	}
   126  	if err := validation.Validate([]validation.Validation{
   127  		{TargetValue: client.SubscriptionID,
   128  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   129  		return result, validation.NewError("metrics.DefinitionsClient", "ListAtSubscriptionScope", err.Error())
   130  	}
   131  
   132  	req, err := client.ListAtSubscriptionScopePreparer(ctx, region, metricnamespace)
   133  	if err != nil {
   134  		err = autorest.NewErrorWithError(err, "metrics.DefinitionsClient", "ListAtSubscriptionScope", nil, "Failure preparing request")
   135  		return
   136  	}
   137  
   138  	resp, err := client.ListAtSubscriptionScopeSender(req)
   139  	if err != nil {
   140  		result.Response = autorest.Response{Response: resp}
   141  		err = autorest.NewErrorWithError(err, "metrics.DefinitionsClient", "ListAtSubscriptionScope", resp, "Failure sending request")
   142  		return
   143  	}
   144  
   145  	result, err = client.ListAtSubscriptionScopeResponder(resp)
   146  	if err != nil {
   147  		err = autorest.NewErrorWithError(err, "metrics.DefinitionsClient", "ListAtSubscriptionScope", resp, "Failure responding to request")
   148  		return
   149  	}
   150  
   151  	return
   152  }
   153  
   154  // ListAtSubscriptionScopePreparer prepares the ListAtSubscriptionScope request.
   155  func (client DefinitionsClient) ListAtSubscriptionScopePreparer(ctx context.Context, region string, metricnamespace string) (*http.Request, error) {
   156  	pathParameters := map[string]interface{}{
   157  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   158  	}
   159  
   160  	const APIVersion = "2021-05-01"
   161  	queryParameters := map[string]interface{}{
   162  		"api-version": APIVersion,
   163  		"region":      autorest.Encode("query", region),
   164  	}
   165  	if len(metricnamespace) > 0 {
   166  		queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace)
   167  	}
   168  
   169  	preparer := autorest.CreatePreparer(
   170  		autorest.AsGet(),
   171  		autorest.WithBaseURL(client.BaseURI),
   172  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Insights/metricDefinitions", pathParameters),
   173  		autorest.WithQueryParameters(queryParameters))
   174  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   175  }
   176  
   177  // ListAtSubscriptionScopeSender sends the ListAtSubscriptionScope request. The method will close the
   178  // http.Response Body if it receives an error.
   179  func (client DefinitionsClient) ListAtSubscriptionScopeSender(req *http.Request) (*http.Response, error) {
   180  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   181  }
   182  
   183  // ListAtSubscriptionScopeResponder handles the response to the ListAtSubscriptionScope request. The method always
   184  // closes the http.Response Body.
   185  func (client DefinitionsClient) ListAtSubscriptionScopeResponder(resp *http.Response) (result SubscriptionScopeMetricDefinitionCollection, err error) {
   186  	err = autorest.Respond(
   187  		resp,
   188  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   189  		autorest.ByUnmarshallingJSON(&result),
   190  		autorest.ByClosing())
   191  	result.Response = autorest.Response{Response: resp}
   192  	return
   193  }
   194  

View as plain text