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