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