1 package locks
2
3
4
5
6
7
8
9 import (
10 "context"
11 "encoding/json"
12 "github.com/Azure/go-autorest/autorest"
13 "github.com/Azure/go-autorest/autorest/to"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 const fqdn = "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-09-01/locks"
20
21
22 type ManagementLockListResult struct {
23 autorest.Response `json:"-"`
24
25 Value *[]ManagementLockObject `json:"value,omitempty"`
26
27 NextLink *string `json:"nextLink,omitempty"`
28 }
29
30
31 type ManagementLockListResultIterator struct {
32 i int
33 page ManagementLockListResultPage
34 }
35
36
37
38 func (iter *ManagementLockListResultIterator) NextWithContext(ctx context.Context) (err error) {
39 if tracing.IsEnabled() {
40 ctx = tracing.StartSpan(ctx, fqdn+"/ManagementLockListResultIterator.NextWithContext")
41 defer func() {
42 sc := -1
43 if iter.Response().Response.Response != nil {
44 sc = iter.Response().Response.Response.StatusCode
45 }
46 tracing.EndSpan(ctx, sc, err)
47 }()
48 }
49 iter.i++
50 if iter.i < len(iter.page.Values()) {
51 return nil
52 }
53 err = iter.page.NextWithContext(ctx)
54 if err != nil {
55 iter.i--
56 return err
57 }
58 iter.i = 0
59 return nil
60 }
61
62
63
64
65 func (iter *ManagementLockListResultIterator) Next() error {
66 return iter.NextWithContext(context.Background())
67 }
68
69
70 func (iter ManagementLockListResultIterator) NotDone() bool {
71 return iter.page.NotDone() && iter.i < len(iter.page.Values())
72 }
73
74
75 func (iter ManagementLockListResultIterator) Response() ManagementLockListResult {
76 return iter.page.Response()
77 }
78
79
80
81 func (iter ManagementLockListResultIterator) Value() ManagementLockObject {
82 if !iter.page.NotDone() {
83 return ManagementLockObject{}
84 }
85 return iter.page.Values()[iter.i]
86 }
87
88
89 func NewManagementLockListResultIterator(page ManagementLockListResultPage) ManagementLockListResultIterator {
90 return ManagementLockListResultIterator{page: page}
91 }
92
93
94 func (mllr ManagementLockListResult) IsEmpty() bool {
95 return mllr.Value == nil || len(*mllr.Value) == 0
96 }
97
98
99 func (mllr ManagementLockListResult) hasNextLink() bool {
100 return mllr.NextLink != nil && len(*mllr.NextLink) != 0
101 }
102
103
104
105 func (mllr ManagementLockListResult) managementLockListResultPreparer(ctx context.Context) (*http.Request, error) {
106 if !mllr.hasNextLink() {
107 return nil, nil
108 }
109 return autorest.Prepare((&http.Request{}).WithContext(ctx),
110 autorest.AsJSON(),
111 autorest.AsGet(),
112 autorest.WithBaseURL(to.String(mllr.NextLink)))
113 }
114
115
116 type ManagementLockListResultPage struct {
117 fn func(context.Context, ManagementLockListResult) (ManagementLockListResult, error)
118 mllr ManagementLockListResult
119 }
120
121
122
123 func (page *ManagementLockListResultPage) NextWithContext(ctx context.Context) (err error) {
124 if tracing.IsEnabled() {
125 ctx = tracing.StartSpan(ctx, fqdn+"/ManagementLockListResultPage.NextWithContext")
126 defer func() {
127 sc := -1
128 if page.Response().Response.Response != nil {
129 sc = page.Response().Response.Response.StatusCode
130 }
131 tracing.EndSpan(ctx, sc, err)
132 }()
133 }
134 for {
135 next, err := page.fn(ctx, page.mllr)
136 if err != nil {
137 return err
138 }
139 page.mllr = next
140 if !next.hasNextLink() || !next.IsEmpty() {
141 break
142 }
143 }
144 return nil
145 }
146
147
148
149
150 func (page *ManagementLockListResultPage) Next() error {
151 return page.NextWithContext(context.Background())
152 }
153
154
155 func (page ManagementLockListResultPage) NotDone() bool {
156 return !page.mllr.IsEmpty()
157 }
158
159
160 func (page ManagementLockListResultPage) Response() ManagementLockListResult {
161 return page.mllr
162 }
163
164
165 func (page ManagementLockListResultPage) Values() []ManagementLockObject {
166 if page.mllr.IsEmpty() {
167 return nil
168 }
169 return *page.mllr.Value
170 }
171
172
173 func NewManagementLockListResultPage(cur ManagementLockListResult, getNextPage func(context.Context, ManagementLockListResult) (ManagementLockListResult, error)) ManagementLockListResultPage {
174 return ManagementLockListResultPage{
175 fn: getNextPage,
176 mllr: cur,
177 }
178 }
179
180
181 type ManagementLockObject struct {
182 autorest.Response `json:"-"`
183
184 *ManagementLockProperties `json:"properties,omitempty"`
185
186 ID *string `json:"id,omitempty"`
187
188 Type *string `json:"type,omitempty"`
189
190 Name *string `json:"name,omitempty"`
191 }
192
193
194 func (mlo ManagementLockObject) MarshalJSON() ([]byte, error) {
195 objectMap := make(map[string]interface{})
196 if mlo.ManagementLockProperties != nil {
197 objectMap["properties"] = mlo.ManagementLockProperties
198 }
199 return json.Marshal(objectMap)
200 }
201
202
203 func (mlo *ManagementLockObject) UnmarshalJSON(body []byte) error {
204 var m map[string]*json.RawMessage
205 err := json.Unmarshal(body, &m)
206 if err != nil {
207 return err
208 }
209 for k, v := range m {
210 switch k {
211 case "properties":
212 if v != nil {
213 var managementLockProperties ManagementLockProperties
214 err = json.Unmarshal(*v, &managementLockProperties)
215 if err != nil {
216 return err
217 }
218 mlo.ManagementLockProperties = &managementLockProperties
219 }
220 case "id":
221 if v != nil {
222 var ID string
223 err = json.Unmarshal(*v, &ID)
224 if err != nil {
225 return err
226 }
227 mlo.ID = &ID
228 }
229 case "type":
230 if v != nil {
231 var typeVar string
232 err = json.Unmarshal(*v, &typeVar)
233 if err != nil {
234 return err
235 }
236 mlo.Type = &typeVar
237 }
238 case "name":
239 if v != nil {
240 var name string
241 err = json.Unmarshal(*v, &name)
242 if err != nil {
243 return err
244 }
245 mlo.Name = &name
246 }
247 }
248 }
249
250 return nil
251 }
252
253
254 type ManagementLockOwner struct {
255
256 ApplicationID *string `json:"applicationId,omitempty"`
257 }
258
259
260 type ManagementLockProperties struct {
261
262 Level LockLevel `json:"level,omitempty"`
263
264 Notes *string `json:"notes,omitempty"`
265
266 Owners *[]ManagementLockOwner `json:"owners,omitempty"`
267 }
268
269
270 type Operation struct {
271
272 Name *string `json:"name,omitempty"`
273
274 Display *OperationDisplay `json:"display,omitempty"`
275 }
276
277
278 type OperationDisplay struct {
279
280 Provider *string `json:"provider,omitempty"`
281
282 Resource *string `json:"resource,omitempty"`
283
284 Operation *string `json:"operation,omitempty"`
285 }
286
287
288
289 type OperationListResult struct {
290 autorest.Response `json:"-"`
291
292 Value *[]Operation `json:"value,omitempty"`
293
294 NextLink *string `json:"nextLink,omitempty"`
295 }
296
297
298 type OperationListResultIterator struct {
299 i int
300 page OperationListResultPage
301 }
302
303
304
305 func (iter *OperationListResultIterator) NextWithContext(ctx context.Context) (err error) {
306 if tracing.IsEnabled() {
307 ctx = tracing.StartSpan(ctx, fqdn+"/OperationListResultIterator.NextWithContext")
308 defer func() {
309 sc := -1
310 if iter.Response().Response.Response != nil {
311 sc = iter.Response().Response.Response.StatusCode
312 }
313 tracing.EndSpan(ctx, sc, err)
314 }()
315 }
316 iter.i++
317 if iter.i < len(iter.page.Values()) {
318 return nil
319 }
320 err = iter.page.NextWithContext(ctx)
321 if err != nil {
322 iter.i--
323 return err
324 }
325 iter.i = 0
326 return nil
327 }
328
329
330
331
332 func (iter *OperationListResultIterator) Next() error {
333 return iter.NextWithContext(context.Background())
334 }
335
336
337 func (iter OperationListResultIterator) NotDone() bool {
338 return iter.page.NotDone() && iter.i < len(iter.page.Values())
339 }
340
341
342 func (iter OperationListResultIterator) Response() OperationListResult {
343 return iter.page.Response()
344 }
345
346
347
348 func (iter OperationListResultIterator) Value() Operation {
349 if !iter.page.NotDone() {
350 return Operation{}
351 }
352 return iter.page.Values()[iter.i]
353 }
354
355
356 func NewOperationListResultIterator(page OperationListResultPage) OperationListResultIterator {
357 return OperationListResultIterator{page: page}
358 }
359
360
361 func (olr OperationListResult) IsEmpty() bool {
362 return olr.Value == nil || len(*olr.Value) == 0
363 }
364
365
366 func (olr OperationListResult) hasNextLink() bool {
367 return olr.NextLink != nil && len(*olr.NextLink) != 0
368 }
369
370
371
372 func (olr OperationListResult) operationListResultPreparer(ctx context.Context) (*http.Request, error) {
373 if !olr.hasNextLink() {
374 return nil, nil
375 }
376 return autorest.Prepare((&http.Request{}).WithContext(ctx),
377 autorest.AsJSON(),
378 autorest.AsGet(),
379 autorest.WithBaseURL(to.String(olr.NextLink)))
380 }
381
382
383 type OperationListResultPage struct {
384 fn func(context.Context, OperationListResult) (OperationListResult, error)
385 olr OperationListResult
386 }
387
388
389
390 func (page *OperationListResultPage) NextWithContext(ctx context.Context) (err error) {
391 if tracing.IsEnabled() {
392 ctx = tracing.StartSpan(ctx, fqdn+"/OperationListResultPage.NextWithContext")
393 defer func() {
394 sc := -1
395 if page.Response().Response.Response != nil {
396 sc = page.Response().Response.Response.StatusCode
397 }
398 tracing.EndSpan(ctx, sc, err)
399 }()
400 }
401 for {
402 next, err := page.fn(ctx, page.olr)
403 if err != nil {
404 return err
405 }
406 page.olr = next
407 if !next.hasNextLink() || !next.IsEmpty() {
408 break
409 }
410 }
411 return nil
412 }
413
414
415
416
417 func (page *OperationListResultPage) Next() error {
418 return page.NextWithContext(context.Background())
419 }
420
421
422 func (page OperationListResultPage) NotDone() bool {
423 return !page.olr.IsEmpty()
424 }
425
426
427 func (page OperationListResultPage) Response() OperationListResult {
428 return page.olr
429 }
430
431
432 func (page OperationListResultPage) Values() []Operation {
433 if page.olr.IsEmpty() {
434 return nil
435 }
436 return *page.olr.Value
437 }
438
439
440 func NewOperationListResultPage(cur OperationListResult, getNextPage func(context.Context, OperationListResult) (OperationListResult, error)) OperationListResultPage {
441 return OperationListResultPage{
442 fn: getNextPage,
443 olr: cur,
444 }
445 }
446
View as plain text