...
1 package insights
2
3
4
5
6
7
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
18 type MetricDefinitionsClient struct {
19 BaseClient
20 }
21
22
23 func NewMetricDefinitionsClient(subscriptionID string) MetricDefinitionsClient {
24 return NewMetricDefinitionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29
30 func NewMetricDefinitionsClientWithBaseURI(baseURI string, subscriptionID string) MetricDefinitionsClient {
31 return MetricDefinitionsClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38 func (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
72 func (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
94
95 func (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
100
101 func (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
View as plain text