-
Notifications
You must be signed in to change notification settings - Fork 641
/
Copy pathhyperdrive.go
533 lines (459 loc) · 19.9 KB
/
hyperdrive.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package hyperdrive
import (
"reflect"
"time"
"github.com/cloudflare/cloudflare-go/v4/internal/apijson"
"github.com/cloudflare/cloudflare-go/v4/internal/param"
"github.com/cloudflare/cloudflare-go/v4/option"
"github.com/tidwall/gjson"
)
// HyperdriveService 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 [NewHyperdriveService] method instead.
type HyperdriveService struct {
Options []option.RequestOption
Configs *ConfigService
}
// NewHyperdriveService 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 NewHyperdriveService(opts ...option.RequestOption) (r *HyperdriveService) {
r = &HyperdriveService{}
r.Options = opts
r.Configs = NewConfigService(opts...)
return
}
type Hyperdrive struct {
// Identifier
ID string `json:"id,required"`
Name string `json:"name,required"`
Origin HyperdriveOrigin `json:"origin,required"`
Caching HyperdriveCaching `json:"caching"`
// When the Hyperdrive configuration was created.
CreatedOn time.Time `json:"created_on" format:"date-time"`
// When the Hyperdrive configuration was last modified.
ModifiedOn time.Time `json:"modified_on" format:"date-time"`
JSON hyperdriveJSON `json:"-"`
}
// hyperdriveJSON contains the JSON metadata for the struct [Hyperdrive]
type hyperdriveJSON struct {
ID apijson.Field
Name apijson.Field
Origin apijson.Field
Caching apijson.Field
CreatedOn apijson.Field
ModifiedOn apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Hyperdrive) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r hyperdriveJSON) RawJSON() string {
return r.raw
}
type HyperdriveOrigin struct {
// The name of your origin database.
Database string `json:"database,required"`
// The host (hostname or IP) of your origin database.
Host string `json:"host,required"`
// Specifies the URL scheme used to connect to your origin database.
Scheme HyperdriveOriginScheme `json:"scheme,required"`
// The user of your origin database.
User string `json:"user,required"`
// The Client ID of the Access token to use when connecting to the origin database.
AccessClientID string `json:"access_client_id"`
// The port (default: 5432 for Postgres) of your origin database.
Port int64 `json:"port"`
JSON hyperdriveOriginJSON `json:"-"`
union HyperdriveOriginUnion
}
// hyperdriveOriginJSON contains the JSON metadata for the struct
// [HyperdriveOrigin]
type hyperdriveOriginJSON struct {
Database apijson.Field
Host apijson.Field
Scheme apijson.Field
User apijson.Field
AccessClientID apijson.Field
Port apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r hyperdriveOriginJSON) RawJSON() string {
return r.raw
}
func (r *HyperdriveOrigin) UnmarshalJSON(data []byte) (err error) {
*r = HyperdriveOrigin{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
// AsUnion returns a [HyperdriveOriginUnion] interface which you can cast to the
// specific types for more type safety.
//
// Possible runtime types of the union are
// [hyperdrive.HyperdriveOriginPublicDatabase],
// [hyperdrive.HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnel].
func (r HyperdriveOrigin) AsUnion() HyperdriveOriginUnion {
return r.union
}
// Union satisfied by [hyperdrive.HyperdriveOriginPublicDatabase] or
// [hyperdrive.HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnel].
type HyperdriveOriginUnion interface {
implementsHyperdriveOrigin()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*HyperdriveOriginUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(HyperdriveOriginPublicDatabase{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnel{}),
},
)
}
type HyperdriveOriginPublicDatabase struct {
// The name of your origin database.
Database string `json:"database,required"`
// The host (hostname or IP) of your origin database.
Host string `json:"host,required"`
// The port (default: 5432 for Postgres) of your origin database.
Port int64 `json:"port,required"`
// Specifies the URL scheme used to connect to your origin database.
Scheme HyperdriveOriginPublicDatabaseScheme `json:"scheme,required"`
// The user of your origin database.
User string `json:"user,required"`
JSON hyperdriveOriginPublicDatabaseJSON `json:"-"`
}
// hyperdriveOriginPublicDatabaseJSON contains the JSON metadata for the struct
// [HyperdriveOriginPublicDatabase]
type hyperdriveOriginPublicDatabaseJSON struct {
Database apijson.Field
Host apijson.Field
Port apijson.Field
Scheme apijson.Field
User apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *HyperdriveOriginPublicDatabase) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r hyperdriveOriginPublicDatabaseJSON) RawJSON() string {
return r.raw
}
func (r HyperdriveOriginPublicDatabase) implementsHyperdriveOrigin() {}
// Specifies the URL scheme used to connect to your origin database.
type HyperdriveOriginPublicDatabaseScheme string
const (
HyperdriveOriginPublicDatabaseSchemePostgres HyperdriveOriginPublicDatabaseScheme = "postgres"
HyperdriveOriginPublicDatabaseSchemePostgresql HyperdriveOriginPublicDatabaseScheme = "postgresql"
)
func (r HyperdriveOriginPublicDatabaseScheme) IsKnown() bool {
switch r {
case HyperdriveOriginPublicDatabaseSchemePostgres, HyperdriveOriginPublicDatabaseSchemePostgresql:
return true
}
return false
}
type HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnel struct {
// The Client ID of the Access token to use when connecting to the origin database.
AccessClientID string `json:"access_client_id,required"`
// The name of your origin database.
Database string `json:"database,required"`
// The host (hostname or IP) of your origin database.
Host string `json:"host,required"`
// Specifies the URL scheme used to connect to your origin database.
Scheme HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelScheme `json:"scheme,required"`
// The user of your origin database.
User string `json:"user,required"`
JSON hyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelJSON `json:"-"`
}
// hyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelJSON contains the
// JSON metadata for the struct
// [HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnel]
type hyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelJSON struct {
AccessClientID apijson.Field
Database apijson.Field
Host apijson.Field
Scheme apijson.Field
User apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnel) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r hyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelJSON) RawJSON() string {
return r.raw
}
func (r HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnel) implementsHyperdriveOrigin() {}
// Specifies the URL scheme used to connect to your origin database.
type HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelScheme string
const (
HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelSchemePostgres HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelScheme = "postgres"
HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelSchemePostgresql HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelScheme = "postgresql"
)
func (r HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelScheme) IsKnown() bool {
switch r {
case HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelSchemePostgres, HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelSchemePostgresql:
return true
}
return false
}
// Specifies the URL scheme used to connect to your origin database.
type HyperdriveOriginScheme string
const (
HyperdriveOriginSchemePostgres HyperdriveOriginScheme = "postgres"
HyperdriveOriginSchemePostgresql HyperdriveOriginScheme = "postgresql"
)
func (r HyperdriveOriginScheme) IsKnown() bool {
switch r {
case HyperdriveOriginSchemePostgres, HyperdriveOriginSchemePostgresql:
return true
}
return false
}
type HyperdriveCaching struct {
// When set to true, disables the caching of SQL responses. (Default: false)
Disabled bool `json:"disabled"`
// When present, specifies max duration for which items should persist in the
// cache. Not returned if set to default. (Default: 60)
MaxAge int64 `json:"max_age"`
// When present, indicates the number of seconds cache may serve the response after
// it becomes stale. Not returned if set to default. (Default: 15)
StaleWhileRevalidate int64 `json:"stale_while_revalidate"`
JSON hyperdriveCachingJSON `json:"-"`
union HyperdriveCachingUnion
}
// hyperdriveCachingJSON contains the JSON metadata for the struct
// [HyperdriveCaching]
type hyperdriveCachingJSON struct {
Disabled apijson.Field
MaxAge apijson.Field
StaleWhileRevalidate apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r hyperdriveCachingJSON) RawJSON() string {
return r.raw
}
func (r *HyperdriveCaching) UnmarshalJSON(data []byte) (err error) {
*r = HyperdriveCaching{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
// AsUnion returns a [HyperdriveCachingUnion] interface which you can cast to the
// specific types for more type safety.
//
// Possible runtime types of the union are
// [hyperdrive.HyperdriveCachingHyperdriveHyperdriveCachingCommon],
// [hyperdrive.HyperdriveCachingHyperdriveHyperdriveCachingEnabled].
func (r HyperdriveCaching) AsUnion() HyperdriveCachingUnion {
return r.union
}
// Union satisfied by
// [hyperdrive.HyperdriveCachingHyperdriveHyperdriveCachingCommon] or
// [hyperdrive.HyperdriveCachingHyperdriveHyperdriveCachingEnabled].
type HyperdriveCachingUnion interface {
implementsHyperdriveCaching()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*HyperdriveCachingUnion)(nil)).Elem(),
"disabled",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(HyperdriveCachingHyperdriveHyperdriveCachingCommon{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(HyperdriveCachingHyperdriveHyperdriveCachingEnabled{}),
},
)
}
type HyperdriveCachingHyperdriveHyperdriveCachingCommon struct {
// When set to true, disables the caching of SQL responses. (Default: false)
Disabled bool `json:"disabled"`
JSON hyperdriveCachingHyperdriveHyperdriveCachingCommonJSON `json:"-"`
}
// hyperdriveCachingHyperdriveHyperdriveCachingCommonJSON contains the JSON
// metadata for the struct [HyperdriveCachingHyperdriveHyperdriveCachingCommon]
type hyperdriveCachingHyperdriveHyperdriveCachingCommonJSON struct {
Disabled apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *HyperdriveCachingHyperdriveHyperdriveCachingCommon) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r hyperdriveCachingHyperdriveHyperdriveCachingCommonJSON) RawJSON() string {
return r.raw
}
func (r HyperdriveCachingHyperdriveHyperdriveCachingCommon) implementsHyperdriveCaching() {}
type HyperdriveCachingHyperdriveHyperdriveCachingEnabled struct {
// When set to true, disables the caching of SQL responses. (Default: false)
Disabled bool `json:"disabled"`
// When present, specifies max duration for which items should persist in the
// cache. Not returned if set to default. (Default: 60)
MaxAge int64 `json:"max_age"`
// When present, indicates the number of seconds cache may serve the response after
// it becomes stale. Not returned if set to default. (Default: 15)
StaleWhileRevalidate int64 `json:"stale_while_revalidate"`
JSON hyperdriveCachingHyperdriveHyperdriveCachingEnabledJSON `json:"-"`
}
// hyperdriveCachingHyperdriveHyperdriveCachingEnabledJSON contains the JSON
// metadata for the struct [HyperdriveCachingHyperdriveHyperdriveCachingEnabled]
type hyperdriveCachingHyperdriveHyperdriveCachingEnabledJSON struct {
Disabled apijson.Field
MaxAge apijson.Field
StaleWhileRevalidate apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *HyperdriveCachingHyperdriveHyperdriveCachingEnabled) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r hyperdriveCachingHyperdriveHyperdriveCachingEnabledJSON) RawJSON() string {
return r.raw
}
func (r HyperdriveCachingHyperdriveHyperdriveCachingEnabled) implementsHyperdriveCaching() {}
type HyperdriveParam struct {
Name param.Field[string] `json:"name,required"`
Origin param.Field[HyperdriveOriginUnionParam] `json:"origin,required"`
Caching param.Field[HyperdriveCachingUnionParam] `json:"caching"`
}
func (r HyperdriveParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type HyperdriveOriginParam struct {
// The name of your origin database.
Database param.Field[string] `json:"database,required"`
// The host (hostname or IP) of your origin database.
Host param.Field[string] `json:"host,required"`
// The password required to access your origin database. This value is write-only
// and never returned by the API.
Password param.Field[string] `json:"password,required"`
// Specifies the URL scheme used to connect to your origin database.
Scheme param.Field[HyperdriveOriginScheme] `json:"scheme,required"`
// The user of your origin database.
User param.Field[string] `json:"user,required"`
// The Client ID of the Access token to use when connecting to the origin database.
AccessClientID param.Field[string] `json:"access_client_id"`
// The Client Secret of the Access token to use when connecting to the origin
// database. This value is write-only and never returned by the API.
AccessClientSecret param.Field[string] `json:"access_client_secret"`
// The port (default: 5432 for Postgres) of your origin database.
Port param.Field[int64] `json:"port"`
}
func (r HyperdriveOriginParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r HyperdriveOriginParam) implementsHyperdriveOriginUnionParam() {}
// Satisfied by [hyperdrive.HyperdriveOriginPublicDatabaseParam],
// [hyperdrive.HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelParam],
// [HyperdriveOriginParam].
type HyperdriveOriginUnionParam interface {
implementsHyperdriveOriginUnionParam()
}
type HyperdriveOriginPublicDatabaseParam struct {
// The name of your origin database.
Database param.Field[string] `json:"database,required"`
// The host (hostname or IP) of your origin database.
Host param.Field[string] `json:"host,required"`
// The password required to access your origin database. This value is write-only
// and never returned by the API.
Password param.Field[string] `json:"password,required"`
// The port (default: 5432 for Postgres) of your origin database.
Port param.Field[int64] `json:"port,required"`
// Specifies the URL scheme used to connect to your origin database.
Scheme param.Field[HyperdriveOriginPublicDatabaseScheme] `json:"scheme,required"`
// The user of your origin database.
User param.Field[string] `json:"user,required"`
}
func (r HyperdriveOriginPublicDatabaseParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r HyperdriveOriginPublicDatabaseParam) implementsHyperdriveOriginUnionParam() {}
type HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelParam struct {
// The Client ID of the Access token to use when connecting to the origin database.
AccessClientID param.Field[string] `json:"access_client_id,required"`
// The Client Secret of the Access token to use when connecting to the origin
// database. This value is write-only and never returned by the API.
AccessClientSecret param.Field[string] `json:"access_client_secret,required"`
// The name of your origin database.
Database param.Field[string] `json:"database,required"`
// The host (hostname or IP) of your origin database.
Host param.Field[string] `json:"host,required"`
// The password required to access your origin database. This value is write-only
// and never returned by the API.
Password param.Field[string] `json:"password,required"`
// Specifies the URL scheme used to connect to your origin database.
Scheme param.Field[HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelScheme] `json:"scheme,required"`
// The user of your origin database.
User param.Field[string] `json:"user,required"`
}
func (r HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r HyperdriveOriginAccessProtectedDatabaseBehindCloudflareTunnelParam) implementsHyperdriveOriginUnionParam() {
}
type HyperdriveCachingParam struct {
// When set to true, disables the caching of SQL responses. (Default: false)
Disabled param.Field[bool] `json:"disabled"`
// When present, specifies max duration for which items should persist in the
// cache. Not returned if set to default. (Default: 60)
MaxAge param.Field[int64] `json:"max_age"`
// When present, indicates the number of seconds cache may serve the response after
// it becomes stale. Not returned if set to default. (Default: 15)
StaleWhileRevalidate param.Field[int64] `json:"stale_while_revalidate"`
}
func (r HyperdriveCachingParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r HyperdriveCachingParam) implementsHyperdriveCachingUnionParam() {}
// Satisfied by
// [hyperdrive.HyperdriveCachingHyperdriveHyperdriveCachingCommonParam],
// [hyperdrive.HyperdriveCachingHyperdriveHyperdriveCachingEnabledParam],
// [HyperdriveCachingParam].
type HyperdriveCachingUnionParam interface {
implementsHyperdriveCachingUnionParam()
}
type HyperdriveCachingHyperdriveHyperdriveCachingCommonParam struct {
// When set to true, disables the caching of SQL responses. (Default: false)
Disabled param.Field[bool] `json:"disabled"`
}
func (r HyperdriveCachingHyperdriveHyperdriveCachingCommonParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r HyperdriveCachingHyperdriveHyperdriveCachingCommonParam) implementsHyperdriveCachingUnionParam() {
}
type HyperdriveCachingHyperdriveHyperdriveCachingEnabledParam struct {
// When set to true, disables the caching of SQL responses. (Default: false)
Disabled param.Field[bool] `json:"disabled"`
// When present, specifies max duration for which items should persist in the
// cache. Not returned if set to default. (Default: 60)
MaxAge param.Field[int64] `json:"max_age"`
// When present, indicates the number of seconds cache may serve the response after
// it becomes stale. Not returned if set to default. (Default: 15)
StaleWhileRevalidate param.Field[int64] `json:"stale_while_revalidate"`
}
func (r HyperdriveCachingHyperdriveHyperdriveCachingEnabledParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r HyperdriveCachingHyperdriveHyperdriveCachingEnabledParam) implementsHyperdriveCachingUnionParam() {
}