1package 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
9import (
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// MetricDefinitionsClient is the monitor Management Client
18type MetricDefinitionsClient struct {
19	BaseClient
20}
21
22// NewMetricDefinitionsClient creates an instance of the MetricDefinitionsClient client.
23func NewMetricDefinitionsClient(subscriptionID string) MetricDefinitionsClient {
24	return NewMetricDefinitionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewMetricDefinitionsClientWithBaseURI creates an instance of the MetricDefinitionsClient client using a custom
28// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
29// stack).
30func NewMetricDefinitionsClientWithBaseURI(baseURI string, subscriptionID string) MetricDefinitionsClient {
31	return MetricDefinitionsClient{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 to query metric definitions for.
38func (client MetricDefinitionsClient) List(ctx context.Context, resourceURI string, metricnamespace string) (result MetricDefinitionCollection, err error) {
39	if tracing.IsEnabled() {
40		ctx = tracing.StartSpan(ctx, fqdn+"/MetricDefinitionsClient.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, "insights.MetricDefinitionsClient", "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, "insights.MetricDefinitionsClient", "List", resp, "Failure sending request")
59		return
60	}
61
62	result, err = client.ListResponder(resp)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "insights.MetricDefinitionsClient", "List", resp, "Failure responding to request")
65		return
66	}
67
68	return
69}
70
71// ListPreparer prepares the List request.
72func (client MetricDefinitionsClient) ListPreparer(ctx context.Context, resourceURI string, metricnamespace string) (*http.Request, error) {
73	pathParameters := map[string]interface{}{
74		"resourceUri": resourceURI,
75	}
76
77	const APIVersion = "2018-01-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.
95func (client MetricDefinitionsClient) 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.
101func (client MetricDefinitionsClient) ListResponder(resp *http.Response) (result MetricDefinitionCollection, 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