1package insights 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// MetricDefinitionsClient is the monitor Management Client 29type MetricDefinitionsClient struct { 30 BaseClient 31} 32 33// NewMetricDefinitionsClient creates an instance of the MetricDefinitionsClient client. 34func NewMetricDefinitionsClient(subscriptionID string) MetricDefinitionsClient { 35 return NewMetricDefinitionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewMetricDefinitionsClientWithBaseURI creates an instance of the MetricDefinitionsClient client using a custom 39// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 40// stack). 41func NewMetricDefinitionsClientWithBaseURI(baseURI string, subscriptionID string) MetricDefinitionsClient { 42 return MetricDefinitionsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// List lists the metric definitions for the resource. 46// Parameters: 47// resourceURI - the identifier of the resource. 48// metricnamespace - metric namespace to query metric definitions for. 49func (client MetricDefinitionsClient) List(ctx context.Context, resourceURI string, metricnamespace string) (result MetricDefinitionCollection, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/MetricDefinitionsClient.List") 52 defer func() { 53 sc := -1 54 if result.Response.Response != nil { 55 sc = result.Response.Response.StatusCode 56 } 57 tracing.EndSpan(ctx, sc, err) 58 }() 59 } 60 req, err := client.ListPreparer(ctx, resourceURI, metricnamespace) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "insights.MetricDefinitionsClient", "List", nil, "Failure preparing request") 63 return 64 } 65 66 resp, err := client.ListSender(req) 67 if err != nil { 68 result.Response = autorest.Response{Response: resp} 69 err = autorest.NewErrorWithError(err, "insights.MetricDefinitionsClient", "List", resp, "Failure sending request") 70 return 71 } 72 73 result, err = client.ListResponder(resp) 74 if err != nil { 75 err = autorest.NewErrorWithError(err, "insights.MetricDefinitionsClient", "List", resp, "Failure responding to request") 76 } 77 78 return 79} 80 81// ListPreparer prepares the List request. 82func (client MetricDefinitionsClient) ListPreparer(ctx context.Context, resourceURI string, metricnamespace string) (*http.Request, error) { 83 pathParameters := map[string]interface{}{ 84 "resourceUri": resourceURI, 85 } 86 87 const APIVersion = "2018-01-01" 88 queryParameters := map[string]interface{}{ 89 "api-version": APIVersion, 90 } 91 if len(metricnamespace) > 0 { 92 queryParameters["metricnamespace"] = autorest.Encode("query", metricnamespace) 93 } 94 95 preparer := autorest.CreatePreparer( 96 autorest.AsGet(), 97 autorest.WithBaseURL(client.BaseURI), 98 autorest.WithPathParameters("/{resourceUri}/providers/microsoft.insights/metricDefinitions", pathParameters), 99 autorest.WithQueryParameters(queryParameters)) 100 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 101} 102 103// ListSender sends the List request. The method will close the 104// http.Response Body if it receives an error. 105func (client MetricDefinitionsClient) ListSender(req *http.Request) (*http.Response, error) { 106 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 107} 108 109// ListResponder handles the response to the List request. The method always 110// closes the http.Response Body. 111func (client MetricDefinitionsClient) ListResponder(resp *http.Response) (result MetricDefinitionCollection, err error) { 112 err = autorest.Respond( 113 resp, 114 client.ByInspecting(), 115 azure.WithErrorUnlessStatusCode(http.StatusOK), 116 autorest.ByUnmarshallingJSON(&result), 117 autorest.ByClosing()) 118 result.Response = autorest.Response{Response: resp} 119 return 120} 121