/
queue.go
593 lines (514 loc) · 18.6 KB
/
queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package queues
import (
"context"
"fmt"
"net/http"
"reflect"
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/pagination"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/internal/shared"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/tidwall/gjson"
)
// QueueService contains methods and other services that help with interacting with
// the cloudflare API. Note, unlike clients, this service does not read variables
// from the environment automatically. You should not instantiate this service
// directly, and instead use the [NewQueueService] method instead.
type QueueService struct {
Options []option.RequestOption
Consumers *ConsumerService
Messages *MessageService
}
// NewQueueService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewQueueService(opts ...option.RequestOption) (r *QueueService) {
r = &QueueService{}
r.Options = opts
r.Consumers = NewConsumerService(opts...)
r.Messages = NewMessageService(opts...)
return
}
// Creates a new queue.
func (r *QueueService) New(ctx context.Context, params QueueNewParams, opts ...option.RequestOption) (res *QueueCreated, err error) {
opts = append(r.Options[:], opts...)
var env QueueNewResponseEnvelope
path := fmt.Sprintf("accounts/%s/queues", params.AccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Updates a queue.
func (r *QueueService) Update(ctx context.Context, queueID string, params QueueUpdateParams, opts ...option.RequestOption) (res *QueueUpdated, err error) {
opts = append(r.Options[:], opts...)
var env QueueUpdateResponseEnvelope
path := fmt.Sprintf("accounts/%s/queues/%s", params.AccountID, queueID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Returns the queues owned by an account.
func (r *QueueService) List(ctx context.Context, query QueueListParams, opts ...option.RequestOption) (res *pagination.SinglePage[Queue], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := fmt.Sprintf("accounts/%s/queues", query.AccountID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Returns the queues owned by an account.
func (r *QueueService) ListAutoPaging(ctx context.Context, query QueueListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[Queue] {
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
}
// Deletes a queue.
func (r *QueueService) Delete(ctx context.Context, queueID string, params QueueDeleteParams, opts ...option.RequestOption) (res *QueueDeleteResponseUnion, err error) {
opts = append(r.Options[:], opts...)
var env QueueDeleteResponseEnvelope
path := fmt.Sprintf("accounts/%s/queues/%s", params.AccountID, queueID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Get information about a specific queue.
func (r *QueueService) Get(ctx context.Context, queueID string, query QueueGetParams, opts ...option.RequestOption) (res *Queue, err error) {
opts = append(r.Options[:], opts...)
var env QueueGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/queues/%s", query.AccountID, queueID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type Queue struct {
Consumers interface{} `json:"consumers"`
ConsumersTotalCount interface{} `json:"consumers_total_count"`
CreatedOn interface{} `json:"created_on"`
ModifiedOn interface{} `json:"modified_on"`
Producers interface{} `json:"producers"`
ProducersTotalCount interface{} `json:"producers_total_count"`
QueueID string `json:"queue_id"`
QueueName string `json:"queue_name"`
JSON queueJSON `json:"-"`
}
// queueJSON contains the JSON metadata for the struct [Queue]
type queueJSON struct {
Consumers apijson.Field
ConsumersTotalCount apijson.Field
CreatedOn apijson.Field
ModifiedOn apijson.Field
Producers apijson.Field
ProducersTotalCount apijson.Field
QueueID apijson.Field
QueueName apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Queue) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r queueJSON) RawJSON() string {
return r.raw
}
type QueueCreated struct {
CreatedOn interface{} `json:"created_on"`
ModifiedOn interface{} `json:"modified_on"`
QueueID interface{} `json:"queue_id"`
QueueName string `json:"queue_name"`
JSON queueCreatedJSON `json:"-"`
}
// queueCreatedJSON contains the JSON metadata for the struct [QueueCreated]
type queueCreatedJSON struct {
CreatedOn apijson.Field
ModifiedOn apijson.Field
QueueID apijson.Field
QueueName apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *QueueCreated) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r queueCreatedJSON) RawJSON() string {
return r.raw
}
type QueueUpdated struct {
CreatedOn interface{} `json:"created_on"`
ModifiedOn interface{} `json:"modified_on"`
QueueID interface{} `json:"queue_id"`
QueueName string `json:"queue_name"`
JSON queueUpdatedJSON `json:"-"`
}
// queueUpdatedJSON contains the JSON metadata for the struct [QueueUpdated]
type queueUpdatedJSON struct {
CreatedOn apijson.Field
ModifiedOn apijson.Field
QueueID apijson.Field
QueueName apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *QueueUpdated) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r queueUpdatedJSON) RawJSON() string {
return r.raw
}
// Union satisfied by [queues.QueueDeleteResponseUnknown],
// [queues.QueueDeleteResponseArray] or [shared.UnionString].
type QueueDeleteResponseUnion interface {
ImplementsQueuesQueueDeleteResponseUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*QueueDeleteResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(QueueDeleteResponseArray{}),
},
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}
type QueueDeleteResponseArray []interface{}
func (r QueueDeleteResponseArray) ImplementsQueuesQueueDeleteResponseUnion() {}
type QueueNewParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
Body interface{} `json:"body,required"`
}
func (r QueueNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Body)
}
type QueueNewResponseEnvelope struct {
CreatedOn interface{} `json:"created_on,required"`
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
ModifiedOn interface{} `json:"modified_on,required"`
QueueID interface{} `json:"queue_id,required"`
QueueName interface{} `json:"queue_name,required"`
Result QueueCreated `json:"result,required,nullable"`
// Whether the API call was successful
Success QueueNewResponseEnvelopeSuccess `json:"success,required"`
ResultInfo QueueNewResponseEnvelopeResultInfo `json:"result_info"`
JSON queueNewResponseEnvelopeJSON `json:"-"`
}
// queueNewResponseEnvelopeJSON contains the JSON metadata for the struct
// [QueueNewResponseEnvelope]
type queueNewResponseEnvelopeJSON struct {
CreatedOn apijson.Field
Errors apijson.Field
Messages apijson.Field
ModifiedOn apijson.Field
QueueID apijson.Field
QueueName apijson.Field
Result apijson.Field
Success apijson.Field
ResultInfo apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *QueueNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r queueNewResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type QueueNewResponseEnvelopeSuccess bool
const (
QueueNewResponseEnvelopeSuccessTrue QueueNewResponseEnvelopeSuccess = true
)
func (r QueueNewResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case QueueNewResponseEnvelopeSuccessTrue:
return true
}
return false
}
type QueueNewResponseEnvelopeResultInfo struct {
// Total number of results for the requested service
Count float64 `json:"count"`
// Current page within paginated list of results
Page float64 `json:"page"`
// Number of results per page of results
PerPage float64 `json:"per_page"`
// Total results available without any search parameters
TotalCount float64 `json:"total_count"`
JSON queueNewResponseEnvelopeResultInfoJSON `json:"-"`
}
// queueNewResponseEnvelopeResultInfoJSON contains the JSON metadata for the struct
// [QueueNewResponseEnvelopeResultInfo]
type queueNewResponseEnvelopeResultInfoJSON struct {
Count apijson.Field
Page apijson.Field
PerPage apijson.Field
TotalCount apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *QueueNewResponseEnvelopeResultInfo) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r queueNewResponseEnvelopeResultInfoJSON) RawJSON() string {
return r.raw
}
type QueueUpdateParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
Body interface{} `json:"body,required"`
}
func (r QueueUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Body)
}
type QueueUpdateResponseEnvelope struct {
CreatedOn interface{} `json:"created_on,required"`
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
ModifiedOn interface{} `json:"modified_on,required"`
QueueID interface{} `json:"queue_id,required"`
QueueName interface{} `json:"queue_name,required"`
Result QueueUpdated `json:"result,required,nullable"`
// Whether the API call was successful
Success QueueUpdateResponseEnvelopeSuccess `json:"success,required"`
ResultInfo QueueUpdateResponseEnvelopeResultInfo `json:"result_info"`
JSON queueUpdateResponseEnvelopeJSON `json:"-"`
}
// queueUpdateResponseEnvelopeJSON contains the JSON metadata for the struct
// [QueueUpdateResponseEnvelope]
type queueUpdateResponseEnvelopeJSON struct {
CreatedOn apijson.Field
Errors apijson.Field
Messages apijson.Field
ModifiedOn apijson.Field
QueueID apijson.Field
QueueName apijson.Field
Result apijson.Field
Success apijson.Field
ResultInfo apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *QueueUpdateResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r queueUpdateResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type QueueUpdateResponseEnvelopeSuccess bool
const (
QueueUpdateResponseEnvelopeSuccessTrue QueueUpdateResponseEnvelopeSuccess = true
)
func (r QueueUpdateResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case QueueUpdateResponseEnvelopeSuccessTrue:
return true
}
return false
}
type QueueUpdateResponseEnvelopeResultInfo struct {
// Total number of results for the requested service
Count float64 `json:"count"`
// Current page within paginated list of results
Page float64 `json:"page"`
// Number of results per page of results
PerPage float64 `json:"per_page"`
// Total results available without any search parameters
TotalCount float64 `json:"total_count"`
JSON queueUpdateResponseEnvelopeResultInfoJSON `json:"-"`
}
// queueUpdateResponseEnvelopeResultInfoJSON contains the JSON metadata for the
// struct [QueueUpdateResponseEnvelopeResultInfo]
type queueUpdateResponseEnvelopeResultInfoJSON struct {
Count apijson.Field
Page apijson.Field
PerPage apijson.Field
TotalCount apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *QueueUpdateResponseEnvelopeResultInfo) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r queueUpdateResponseEnvelopeResultInfoJSON) RawJSON() string {
return r.raw
}
type QueueListParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type QueueDeleteParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
Body interface{} `json:"body,required"`
}
func (r QueueDeleteParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Body)
}
type QueueDeleteResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result QueueDeleteResponseUnion `json:"result,required,nullable"`
// Whether the API call was successful
Success QueueDeleteResponseEnvelopeSuccess `json:"success,required"`
ResultInfo QueueDeleteResponseEnvelopeResultInfo `json:"result_info"`
JSON queueDeleteResponseEnvelopeJSON `json:"-"`
}
// queueDeleteResponseEnvelopeJSON contains the JSON metadata for the struct
// [QueueDeleteResponseEnvelope]
type queueDeleteResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
ResultInfo apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *QueueDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r queueDeleteResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type QueueDeleteResponseEnvelopeSuccess bool
const (
QueueDeleteResponseEnvelopeSuccessTrue QueueDeleteResponseEnvelopeSuccess = true
)
func (r QueueDeleteResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case QueueDeleteResponseEnvelopeSuccessTrue:
return true
}
return false
}
type QueueDeleteResponseEnvelopeResultInfo struct {
// Total number of results for the requested service
Count float64 `json:"count"`
// Current page within paginated list of results
Page float64 `json:"page"`
// Number of results per page of results
PerPage float64 `json:"per_page"`
// Total results available without any search parameters
TotalCount float64 `json:"total_count"`
JSON queueDeleteResponseEnvelopeResultInfoJSON `json:"-"`
}
// queueDeleteResponseEnvelopeResultInfoJSON contains the JSON metadata for the
// struct [QueueDeleteResponseEnvelopeResultInfo]
type queueDeleteResponseEnvelopeResultInfoJSON struct {
Count apijson.Field
Page apijson.Field
PerPage apijson.Field
TotalCount apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *QueueDeleteResponseEnvelopeResultInfo) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r queueDeleteResponseEnvelopeResultInfoJSON) RawJSON() string {
return r.raw
}
type QueueGetParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type QueueGetResponseEnvelope struct {
CreatedOn interface{} `json:"created_on,required"`
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
ModifiedOn interface{} `json:"modified_on,required"`
QueueID interface{} `json:"queue_id,required"`
QueueName interface{} `json:"queue_name,required"`
Result Queue `json:"result,required,nullable"`
// Whether the API call was successful
Success QueueGetResponseEnvelopeSuccess `json:"success,required"`
ResultInfo QueueGetResponseEnvelopeResultInfo `json:"result_info"`
JSON queueGetResponseEnvelopeJSON `json:"-"`
}
// queueGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [QueueGetResponseEnvelope]
type queueGetResponseEnvelopeJSON struct {
CreatedOn apijson.Field
Errors apijson.Field
Messages apijson.Field
ModifiedOn apijson.Field
QueueID apijson.Field
QueueName apijson.Field
Result apijson.Field
Success apijson.Field
ResultInfo apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *QueueGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r queueGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type QueueGetResponseEnvelopeSuccess bool
const (
QueueGetResponseEnvelopeSuccessTrue QueueGetResponseEnvelopeSuccess = true
)
func (r QueueGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case QueueGetResponseEnvelopeSuccessTrue:
return true
}
return false
}
type QueueGetResponseEnvelopeResultInfo struct {
// Total number of results for the requested service
Count float64 `json:"count"`
// Current page within paginated list of results
Page float64 `json:"page"`
// Number of results per page of results
PerPage float64 `json:"per_page"`
// Total results available without any search parameters
TotalCount float64 `json:"total_count"`
JSON queueGetResponseEnvelopeResultInfoJSON `json:"-"`
}
// queueGetResponseEnvelopeResultInfoJSON contains the JSON metadata for the struct
// [QueueGetResponseEnvelopeResultInfo]
type queueGetResponseEnvelopeResultInfoJSON struct {
Count apijson.Field
Page apijson.Field
PerPage apijson.Field
TotalCount apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *QueueGetResponseEnvelopeResultInfo) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r queueGetResponseEnvelopeResultInfoJSON) RawJSON() string {
return r.raw
}