1package storagecache
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 a Storage Cache provides scalable caching service for NAS clients, serving data from either
18// NFSv3 or Blob at-rest storage (referred to as "Storage Targets"). These operations allow you to manage Caches.
19type OperationsClient struct {
20	BaseClient
21}
22
23// NewOperationsClient creates an instance of the OperationsClient client.
24func NewOperationsClient(subscriptionID string) OperationsClient {
25	return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client using a custom endpoint.  Use this
29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient {
31	return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// List lists all of the available Resource Provider operations.
35func (client OperationsClient) List(ctx context.Context) (result APIOperationListResultPage, err error) {
36	if tracing.IsEnabled() {
37		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
38		defer func() {
39			sc := -1
40			if result.aolr.Response.Response != nil {
41				sc = result.aolr.Response.Response.StatusCode
42			}
43			tracing.EndSpan(ctx, sc, err)
44		}()
45	}
46	result.fn = client.listNextResults
47	req, err := client.ListPreparer(ctx)
48	if err != nil {
49		err = autorest.NewErrorWithError(err, "storagecache.OperationsClient", "List", nil, "Failure preparing request")
50		return
51	}
52
53	resp, err := client.ListSender(req)
54	if err != nil {
55		result.aolr.Response = autorest.Response{Response: resp}
56		err = autorest.NewErrorWithError(err, "storagecache.OperationsClient", "List", resp, "Failure sending request")
57		return
58	}
59
60	result.aolr, err = client.ListResponder(resp)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "storagecache.OperationsClient", "List", resp, "Failure responding to request")
63		return
64	}
65	if result.aolr.hasNextLink() && result.aolr.IsEmpty() {
66		err = result.NextWithContext(ctx)
67		return
68	}
69
70	return
71}
72
73// ListPreparer prepares the List request.
74func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
75	const APIVersion = "2020-03-01"
76	queryParameters := map[string]interface{}{
77		"api-version": APIVersion,
78	}
79
80	preparer := autorest.CreatePreparer(
81		autorest.AsGet(),
82		autorest.WithBaseURL(client.BaseURI),
83		autorest.WithPath("/providers/Microsoft.StorageCache/operations"),
84		autorest.WithQueryParameters(queryParameters))
85	return preparer.Prepare((&http.Request{}).WithContext(ctx))
86}
87
88// ListSender sends the List request. The method will close the
89// http.Response Body if it receives an error.
90func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) {
91	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
92}
93
94// ListResponder handles the response to the List request. The method always
95// closes the http.Response Body.
96func (client OperationsClient) ListResponder(resp *http.Response) (result APIOperationListResult, err error) {
97	err = autorest.Respond(
98		resp,
99		azure.WithErrorUnlessStatusCode(http.StatusOK),
100		autorest.ByUnmarshallingJSON(&result),
101		autorest.ByClosing())
102	result.Response = autorest.Response{Response: resp}
103	return
104}
105
106// listNextResults retrieves the next set of results, if any.
107func (client OperationsClient) listNextResults(ctx context.Context, lastResults APIOperationListResult) (result APIOperationListResult, err error) {
108	req, err := lastResults.aPIOperationListResultPreparer(ctx)
109	if err != nil {
110		return result, autorest.NewErrorWithError(err, "storagecache.OperationsClient", "listNextResults", nil, "Failure preparing next results request")
111	}
112	if req == nil {
113		return
114	}
115	resp, err := client.ListSender(req)
116	if err != nil {
117		result.Response = autorest.Response{Response: resp}
118		return result, autorest.NewErrorWithError(err, "storagecache.OperationsClient", "listNextResults", resp, "Failure sending next results request")
119	}
120	result, err = client.ListResponder(resp)
121	if err != nil {
122		err = autorest.NewErrorWithError(err, "storagecache.OperationsClient", "listNextResults", resp, "Failure responding to next results request")
123	}
124	return
125}
126
127// ListComplete enumerates all values, automatically crossing page boundaries as required.
128func (client OperationsClient) ListComplete(ctx context.Context) (result APIOperationListResultIterator, err error) {
129	if tracing.IsEnabled() {
130		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
131		defer func() {
132			sc := -1
133			if result.Response().Response.Response != nil {
134				sc = result.page.Response().Response.Response.StatusCode
135			}
136			tracing.EndSpan(ctx, sc, err)
137		}()
138	}
139	result.page, err = client.List(ctx)
140	return
141}
142