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/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 type MetricDefinitionsClient struct {
20 BaseClient
21 }
22
23
24 func NewMetricDefinitionsClient(subscriptionID string) MetricDefinitionsClient {
25 return NewMetricDefinitionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30
31 func NewMetricDefinitionsClientWithBaseURI(baseURI string, subscriptionID string) MetricDefinitionsClient {
32 return MetricDefinitionsClient{NewWithBaseURI(baseURI, subscriptionID)}
33 }
34
35
36
37
38
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
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
101
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
107
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