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// OperationsClient is the monitor Management Client
18type OperationsClient struct {
19	BaseClient
20}
21
22// NewOperationsClient creates an instance of the OperationsClient client.
23func NewOperationsClient(subscriptionID string) OperationsClient {
24	return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client using a custom endpoint.  Use this
28// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
29func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient {
30	return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
31}
32
33// List lists all of the available operations from Microsoft.Insights provider.
34func (client OperationsClient) List(ctx context.Context) (result OperationListResult, err error) {
35	if tracing.IsEnabled() {
36		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
37		defer func() {
38			sc := -1
39			if result.Response.Response != nil {
40				sc = result.Response.Response.StatusCode
41			}
42			tracing.EndSpan(ctx, sc, err)
43		}()
44	}
45	req, err := client.ListPreparer(ctx)
46	if err != nil {
47		err = autorest.NewErrorWithError(err, "insights.OperationsClient", "List", nil, "Failure preparing request")
48		return
49	}
50
51	resp, err := client.ListSender(req)
52	if err != nil {
53		result.Response = autorest.Response{Response: resp}
54		err = autorest.NewErrorWithError(err, "insights.OperationsClient", "List", resp, "Failure sending request")
55		return
56	}
57
58	result, err = client.ListResponder(resp)
59	if err != nil {
60		err = autorest.NewErrorWithError(err, "insights.OperationsClient", "List", resp, "Failure responding to request")
61		return
62	}
63
64	return
65}
66
67// ListPreparer prepares the List request.
68func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
69	const APIVersion = "2015-04-01"
70	queryParameters := map[string]interface{}{
71		"api-version": APIVersion,
72	}
73
74	preparer := autorest.CreatePreparer(
75		autorest.AsGet(),
76		autorest.WithBaseURL(client.BaseURI),
77		autorest.WithPath("/providers/microsoft.insights/operations"),
78		autorest.WithQueryParameters(queryParameters))
79	return preparer.Prepare((&http.Request{}).WithContext(ctx))
80}
81
82// ListSender sends the List request. The method will close the
83// http.Response Body if it receives an error.
84func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) {
85	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
86}
87
88// ListResponder handles the response to the List request. The method always
89// closes the http.Response Body.
90func (client OperationsClient) ListResponder(resp *http.Response) (result OperationListResult, err error) {
91	err = autorest.Respond(
92		resp,
93		azure.WithErrorUnlessStatusCode(http.StatusOK),
94		autorest.ByUnmarshallingJSON(&result),
95		autorest.ByClosing())
96	result.Response = autorest.Response{Response: resp}
97	return
98}
99