1 package subscriptions
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
19
20 type OperationsClient struct {
21 BaseClient
22 }
23
24
25 func NewOperationsClient() OperationsClient {
26 return NewOperationsClientWithBaseURI(DefaultBaseURI)
27 }
28
29
30
31 func NewOperationsClientWithBaseURI(baseURI string) OperationsClient {
32 return OperationsClient{NewWithBaseURI(baseURI)}
33 }
34
35
36 func (client OperationsClient) List(ctx context.Context) (result OperationListResultPage, err error) {
37 if tracing.IsEnabled() {
38 ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
39 defer func() {
40 sc := -1
41 if result.olr.Response.Response != nil {
42 sc = result.olr.Response.Response.StatusCode
43 }
44 tracing.EndSpan(ctx, sc, err)
45 }()
46 }
47 result.fn = client.listNextResults
48 req, err := client.ListPreparer(ctx)
49 if err != nil {
50 err = autorest.NewErrorWithError(err, "subscriptions.OperationsClient", "List", nil, "Failure preparing request")
51 return
52 }
53
54 resp, err := client.ListSender(req)
55 if err != nil {
56 result.olr.Response = autorest.Response{Response: resp}
57 err = autorest.NewErrorWithError(err, "subscriptions.OperationsClient", "List", resp, "Failure sending request")
58 return
59 }
60
61 result.olr, err = client.ListResponder(resp)
62 if err != nil {
63 err = autorest.NewErrorWithError(err, "subscriptions.OperationsClient", "List", resp, "Failure responding to request")
64 return
65 }
66 if result.olr.hasNextLink() && result.olr.IsEmpty() {
67 err = result.NextWithContext(ctx)
68 return
69 }
70
71 return
72 }
73
74
75 func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
76 const APIVersion = "2016-06-01"
77 queryParameters := map[string]interface{}{
78 "api-version": APIVersion,
79 }
80
81 preparer := autorest.CreatePreparer(
82 autorest.AsGet(),
83 autorest.WithBaseURL(client.BaseURI),
84 autorest.WithPath("/providers/Microsoft.Resources/operations"),
85 autorest.WithQueryParameters(queryParameters))
86 return preparer.Prepare((&http.Request{}).WithContext(ctx))
87 }
88
89
90
91 func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) {
92 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
93 }
94
95
96
97 func (client OperationsClient) ListResponder(resp *http.Response) (result OperationListResult, err error) {
98 err = autorest.Respond(
99 resp,
100 azure.WithErrorUnlessStatusCode(http.StatusOK),
101 autorest.ByUnmarshallingJSON(&result),
102 autorest.ByClosing())
103 result.Response = autorest.Response{Response: resp}
104 return
105 }
106
107
108 func (client OperationsClient) listNextResults(ctx context.Context, lastResults OperationListResult) (result OperationListResult, err error) {
109 req, err := lastResults.operationListResultPreparer(ctx)
110 if err != nil {
111 return result, autorest.NewErrorWithError(err, "subscriptions.OperationsClient", "listNextResults", nil, "Failure preparing next results request")
112 }
113 if req == nil {
114 return
115 }
116 resp, err := client.ListSender(req)
117 if err != nil {
118 result.Response = autorest.Response{Response: resp}
119 return result, autorest.NewErrorWithError(err, "subscriptions.OperationsClient", "listNextResults", resp, "Failure sending next results request")
120 }
121 result, err = client.ListResponder(resp)
122 if err != nil {
123 err = autorest.NewErrorWithError(err, "subscriptions.OperationsClient", "listNextResults", resp, "Failure responding to next results request")
124 }
125 return
126 }
127
128
129 func (client OperationsClient) ListComplete(ctx context.Context) (result OperationListResultIterator, err error) {
130 if tracing.IsEnabled() {
131 ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
132 defer func() {
133 sc := -1
134 if result.Response().Response.Response != nil {
135 sc = result.page.Response().Response.Response.StatusCode
136 }
137 tracing.EndSpan(ctx, sc, err)
138 }()
139 }
140 result.page, err = client.List(ctx)
141 return
142 }
143
View as plain text