1 package dtl
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 type ProviderOperationsClient struct {
19 BaseClient
20 }
21
22
23 func NewProviderOperationsClient(subscriptionID string) ProviderOperationsClient {
24 return NewProviderOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29
30 func NewProviderOperationsClientWithBaseURI(baseURI string, subscriptionID string) ProviderOperationsClient {
31 return ProviderOperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35 func (client ProviderOperationsClient) List(ctx context.Context) (result ProviderOperationResultPage, err error) {
36 if tracing.IsEnabled() {
37 ctx = tracing.StartSpan(ctx, fqdn+"/ProviderOperationsClient.List")
38 defer func() {
39 sc := -1
40 if result.por.Response.Response != nil {
41 sc = result.por.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, "dtl.ProviderOperationsClient", "List", nil, "Failure preparing request")
50 return
51 }
52
53 resp, err := client.ListSender(req)
54 if err != nil {
55 result.por.Response = autorest.Response{Response: resp}
56 err = autorest.NewErrorWithError(err, "dtl.ProviderOperationsClient", "List", resp, "Failure sending request")
57 return
58 }
59
60 result.por, err = client.ListResponder(resp)
61 if err != nil {
62 err = autorest.NewErrorWithError(err, "dtl.ProviderOperationsClient", "List", resp, "Failure responding to request")
63 return
64 }
65 if result.por.hasNextLink() && result.por.IsEmpty() {
66 err = result.NextWithContext(ctx)
67 return
68 }
69
70 return
71 }
72
73
74 func (client ProviderOperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
75 const APIVersion = "2016-05-15"
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.DevTestLab/operations"),
84 autorest.WithQueryParameters(queryParameters))
85 return preparer.Prepare((&http.Request{}).WithContext(ctx))
86 }
87
88
89
90 func (client ProviderOperationsClient) ListSender(req *http.Request) (*http.Response, error) {
91 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
92 }
93
94
95
96 func (client ProviderOperationsClient) ListResponder(resp *http.Response) (result ProviderOperationResult, 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
107 func (client ProviderOperationsClient) listNextResults(ctx context.Context, lastResults ProviderOperationResult) (result ProviderOperationResult, err error) {
108 req, err := lastResults.providerOperationResultPreparer(ctx)
109 if err != nil {
110 return result, autorest.NewErrorWithError(err, "dtl.ProviderOperationsClient", "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, "dtl.ProviderOperationsClient", "listNextResults", resp, "Failure sending next results request")
119 }
120 result, err = client.ListResponder(resp)
121 if err != nil {
122 err = autorest.NewErrorWithError(err, "dtl.ProviderOperationsClient", "listNextResults", resp, "Failure responding to next results request")
123 }
124 return
125 }
126
127
128 func (client ProviderOperationsClient) ListComplete(ctx context.Context) (result ProviderOperationResultIterator, err error) {
129 if tracing.IsEnabled() {
130 ctx = tracing.StartSpan(ctx, fqdn+"/ProviderOperationsClient.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
View as plain text