-
Notifications
You must be signed in to change notification settings - Fork 71
/
options.go
768 lines (654 loc) · 23.2 KB
/
options.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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
package ydb
import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
"os"
"path/filepath"
"time"
"github.com/ydb-platform/ydb-go-sdk/v3/config"
"github.com/ydb-platform/ydb-go-sdk/v3/credentials"
balancerConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/certificates"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
coordinationConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/coordination/config"
discoveryConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/discovery/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/dsn"
queryConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/config"
ratelimiterConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/ratelimiter/config"
schemeConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/scheme/config"
scriptingConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/scripting/config"
tableConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/table/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql"
"github.com/ydb-platform/ydb-go-sdk/v3/log"
"github.com/ydb-platform/ydb-go-sdk/v3/retry/budget"
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topicoptions"
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
)
// Option contains configuration values for Driver
type Option func(ctx context.Context, d *Driver) error
func WithStaticCredentials(user, password string) Option {
return func(ctx context.Context, c *Driver) error {
c.userInfo = &dsn.UserInfo{
User: user,
Password: password,
}
return nil
}
}
// WithNodeAddressMutator applies mutator for node addresses from discovery.ListEndpoints response
//
// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
func WithNodeAddressMutator(mutator func(address string) string) Option {
return func(ctx context.Context, c *Driver) error {
c.discoveryOptions = append(c.discoveryOptions, discoveryConfig.WithAddressMutator(mutator))
return nil
}
}
func WithAccessTokenCredentials(accessToken string) Option {
return WithCredentials(
credentials.NewAccessTokenCredentials(
accessToken,
credentials.WithSourceInfo(
"ydb.WithAccessTokenCredentials(accessToken)", // hide access token for logs
),
),
)
}
// WithOauth2TokenExchangeCredentials adds credentials that exchange token using
// OAuth 2.0 token exchange protocol:
// https://www.rfc-editor.org/rfc/rfc8693
func WithOauth2TokenExchangeCredentials(
opts ...credentials.Oauth2TokenExchangeCredentialsOption,
) Option {
opts = append(opts, credentials.WithSourceInfo("ydb.WithOauth2TokenExchangeCredentials(opts)"))
return WithCreateCredentialsFunc(func(context.Context) (credentials.Credentials, error) {
return credentials.NewOauth2TokenExchangeCredentials(opts...)
})
}
/*
WithOauth2TokenExchangeCredentialsFile adds credentials that exchange token using
OAuth 2.0 token exchange protocol:
https://www.rfc-editor.org/rfc/rfc8693
Config file must be a valid json file
Fields of json file
grant-type: [string] Grant type option (default: "urn:ietf:params:oauth:grant-type:token-exchange")
res: [string | list of strings] Resource option (optional)
aud: [string | list of strings] Audience option for token exchange request (optional)
scope: [string | list of strings] Scope option (optional)
requested-token-type: [string] Requested token type option (default: "urn:ietf:params:oauth:token-type:access_token")
subject-credentials: [creds_json] Subject credentials options (optional)
actor-credentials: [creds_json] Actor credentials options (optional)
token-endpoint: [string] Token endpoint
Fields of creds_json (JWT):
type: [string] Token source type. Set JWT
alg: [string] Algorithm for JWT signature.
Supported algorithms can be listed
with GetSupportedOauth2TokenExchangeJwtAlgorithms()
private-key: [string] (Private) key in PEM format (RSA, EC) or Base64 format (HMAC) for JWT signature
kid: [string] Key id JWT standard claim (optional)
iss: [string] Issuer JWT standard claim (optional)
sub: [string] Subject JWT standard claim (optional)
aud: [string | list of strings] Audience JWT standard claim (optional)
jti: [string] JWT ID JWT standard claim (optional)
ttl: [string] Token TTL (default: 1h)
Fields of creds_json (FIXED):
type: [string] Token source type. Set FIXED
token: [string] Token value
token-type: [string] Token type value. It will become
subject_token_type/actor_token_type parameter
in token exchange request (https://www.rfc-editor.org/rfc/rfc8693)
*/
func WithOauth2TokenExchangeCredentialsFile(
configFilePath string,
opts ...credentials.Oauth2TokenExchangeCredentialsOption,
) Option {
srcInfo := credentials.WithSourceInfo(fmt.Sprintf("ydb.WithOauth2TokenExchangeCredentialsFile(%s)", configFilePath))
opts = append(opts, srcInfo)
return WithCreateCredentialsFunc(func(context.Context) (credentials.Credentials, error) {
return credentials.NewOauth2TokenExchangeCredentialsFile(configFilePath, opts...)
})
}
// WithApplicationName add provided application name to all api requests
func WithApplicationName(applicationName string) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithApplicationName(applicationName))
return nil
}
}
// WithUserAgent add provided user agent value to all api requests
//
// Deprecated: use WithApplicationName instead.
// Will be removed after Oct 2024.
// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
func WithUserAgent(userAgent string) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithApplicationName(userAgent))
return nil
}
}
func WithRequestsType(requestsType string) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithRequestsType(requestsType))
return nil
}
}
// WithConnectionString accept Driver string like
//
// grpc[s]://{endpoint}/{database}[?param=value]
//
// Warning: WithConnectionString will be removed at next major release
//
// (Driver string will be required string param of ydb.Open)
func WithConnectionString(connectionString string) Option {
return func(ctx context.Context, c *Driver) error {
if connectionString == "" {
return nil
}
info, err := dsn.Parse(connectionString)
if err != nil {
return xerrors.WithStackTrace(
fmt.Errorf("parse connection string '%s' failed: %w", connectionString, err),
)
}
c.options = append(c.options, info.Options...)
c.userInfo = info.UserInfo
return nil
}
}
// WithConnectionTTL defines duration for parking idle connections
func WithConnectionTTL(ttl time.Duration) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithConnectionTTL(ttl))
return nil
}
}
// WithEndpoint defines endpoint option
//
// Warning: use ydb.Open with required Driver string parameter instead
//
// For making Driver string from endpoint+database+secure - use sugar.DSN()
func WithEndpoint(endpoint string) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithEndpoint(endpoint))
return nil
}
}
// WithDatabase defines database option
//
// Warning: use ydb.Open with required Driver string parameter instead
//
// For making Driver string from endpoint+database+secure - use sugar.DSN()
func WithDatabase(database string) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithDatabase(database))
return nil
}
}
// WithSecure defines secure option
//
// Warning: use ydb.Open with required Driver string parameter instead
//
// For making Driver string from endpoint+database+secure - use sugar.DSN()
func WithSecure(secure bool) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithSecure(secure))
return nil
}
}
// WithInsecure defines secure option.
//
// Warning: WithInsecure lost current TLS config.
func WithInsecure() Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithSecure(false))
return nil
}
}
// WithMinTLSVersion set minimum TLS version acceptable for connections
func WithMinTLSVersion(minVersion uint16) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithMinTLSVersion(minVersion))
return nil
}
}
// WithTLSSInsecureSkipVerify applies InsecureSkipVerify flag to TLS config
func WithTLSSInsecureSkipVerify() Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithTLSSInsecureSkipVerify())
return nil
}
}
// WithLogger add enables logging for selected tracing events.
//
// See trace package documentation for details.
func WithLogger(l log.Logger, details trace.Detailer, opts ...log.Option) Option {
return func(ctx context.Context, c *Driver) error {
c.logger = l
c.loggerOpts = opts
c.loggerDetails = details
return nil
}
}
// WithAnonymousCredentials force to make requests withou authentication.
func WithAnonymousCredentials() Option {
return WithCredentials(
credentials.NewAnonymousCredentials(credentials.WithSourceInfo("ydb.WithAnonymousCredentials()")),
)
}
// WithCreateCredentialsFunc add callback funcion to provide requests credentials
func WithCreateCredentialsFunc(createCredentials func(ctx context.Context) (credentials.Credentials, error)) Option {
return func(ctx context.Context, c *Driver) error {
creds, err := createCredentials(ctx)
if err != nil {
return xerrors.WithStackTrace(err)
}
c.options = append(c.options, config.WithCredentials(creds))
return nil
}
}
// WithCredentials in conjunction with Driver.With function prohibit reuse of conn pool.
// Thus, Driver.With will effectively create totally separate Driver.
func WithCredentials(c credentials.Credentials) Option {
return WithCreateCredentialsFunc(func(context.Context) (credentials.Credentials, error) {
return c, nil
})
}
func WithBalancer(balancer *balancerConfig.Config) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithBalancer(balancer))
return nil
}
}
// WithDialTimeout sets timeout for establishing new Driver to cluster
//
// Default dial timeout is config.DefaultDialTimeout
func WithDialTimeout(timeout time.Duration) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithDialTimeout(timeout))
return nil
}
}
// With collects additional configuration options.
//
// This option does not replace collected option, instead it will append provided options.
func With(options ...config.Option) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, options...)
return nil
}
}
// MergeOptions concatentaes provided options to one cumulative value.
func MergeOptions(opts ...Option) Option {
return func(ctx context.Context, c *Driver) error {
for _, opt := range opts {
if opt != nil {
if err := opt(ctx, c); err != nil {
return xerrors.WithStackTrace(err)
}
}
}
return nil
}
}
// WithDiscoveryInterval sets interval between cluster discovery calls.
func WithDiscoveryInterval(discoveryInterval time.Duration) Option {
return func(ctx context.Context, c *Driver) error {
c.discoveryOptions = append(c.discoveryOptions, discoveryConfig.WithInterval(discoveryInterval))
return nil
}
}
// WithRetryBudget sets retry budget for all calls of all retryers.
//
// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
func WithRetryBudget(b budget.Budget) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithRetryBudget(b))
return nil
}
}
// WithTraceDriver appends trace.Driver into driver traces
func WithTraceDriver(t trace.Driver, opts ...trace.DriverComposeOption) Option { //nolint:gocritic
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithTrace(t, opts...))
return nil
}
}
// WithTraceRetry appends trace.Retry into retry traces
func WithTraceRetry(t trace.Retry, opts ...trace.RetryComposeOption) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options,
config.WithTraceRetry(&t, append(
[]trace.RetryComposeOption{
trace.WithRetryPanicCallback(c.panicCallback),
},
opts...,
)...),
)
return nil
}
}
// WithCertificate appends certificate to TLS config root certificates
func WithCertificate(cert *x509.Certificate) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithCertificate(cert))
return nil
}
}
// WithCertificatesFromFile appends certificates by filepath to TLS config root certificates
func WithCertificatesFromFile(caFile string, opts ...certificates.FromFileOption) Option {
if len(caFile) > 0 && caFile[0] == '~' {
if home, err := os.UserHomeDir(); err == nil {
caFile = filepath.Join(home, caFile[1:])
}
}
if file, err := filepath.Abs(caFile); err == nil {
caFile = file
}
if file, err := filepath.EvalSymlinks(caFile); err == nil {
caFile = file
}
return func(ctx context.Context, c *Driver) error {
certs, err := certificates.FromFile(caFile, opts...)
if err != nil {
return xerrors.WithStackTrace(err)
}
for _, cert := range certs {
if err := WithCertificate(cert)(ctx, c); err != nil {
return xerrors.WithStackTrace(err)
}
}
return nil
}
}
// WithTLSConfig replaces older TLS config
//
// Warning: all early TLS config changes (such as WithCertificate, WithCertificatesFromFile, WithCertificatesFromPem,
// WithMinTLSVersion, WithTLSSInsecureSkipVerify) will be lost
func WithTLSConfig(tlsConfig *tls.Config) Option {
return func(ctx context.Context, c *Driver) error {
c.options = append(c.options, config.WithTLSConfig(tlsConfig))
return nil
}
}
// WithCertificatesFromPem appends certificates from pem-encoded data to TLS config root certificates
func WithCertificatesFromPem(bytes []byte, opts ...certificates.FromPemOption) Option {
return func(ctx context.Context, c *Driver) error {
certs, err := certificates.FromPem(bytes, opts...)
if err != nil {
return xerrors.WithStackTrace(err)
}
for _, cert := range certs {
_ = WithCertificate(cert)(ctx, c)
}
return nil
}
}
// WithTableConfigOption collects additional configuration options for table.Client.
// This option does not replace collected option, instead it will appen provided options.
func WithTableConfigOption(option tableConfig.Option) Option {
return func(ctx context.Context, c *Driver) error {
c.tableOptions = append(c.tableOptions, option)
return nil
}
}
// WithQueryConfigOption collects additional configuration options for query.Client.
// This option does not replace collected option, instead it will appen provided options.
func WithQueryConfigOption(option queryConfig.Option) Option {
return func(ctx context.Context, c *Driver) error {
c.queryOptions = append(c.queryOptions, option)
return nil
}
}
// WithSessionPoolSizeLimit set max size of internal sessions pool in table.Client
func WithSessionPoolSizeLimit(sizeLimit int) Option {
return func(ctx context.Context, c *Driver) error {
c.tableOptions = append(c.tableOptions, tableConfig.WithSizeLimit(sizeLimit))
c.queryOptions = append(c.queryOptions, queryConfig.WithPoolLimit(sizeLimit))
return nil
}
}
// WithSessionPoolIdleThreshold defines interval for idle sessions
func WithSessionPoolIdleThreshold(idleThreshold time.Duration) Option {
return func(ctx context.Context, c *Driver) error {
c.tableOptions = append(c.tableOptions, tableConfig.WithIdleThreshold(idleThreshold))
c.databaseSQLOptions = append(
c.databaseSQLOptions,
xsql.WithIdleThreshold(idleThreshold),
)
return nil
}
}
// WithSessionPoolCreateSessionTimeout set timeout for new session creation process in table.Client
func WithSessionPoolCreateSessionTimeout(createSessionTimeout time.Duration) Option {
return func(ctx context.Context, c *Driver) error {
c.tableOptions = append(c.tableOptions, tableConfig.WithCreateSessionTimeout(createSessionTimeout))
c.queryOptions = append(c.queryOptions, queryConfig.WithSessionCreateTimeout(createSessionTimeout))
return nil
}
}
// WithSessionPoolDeleteTimeout set timeout to gracefully close deleting session in table.Client
func WithSessionPoolDeleteTimeout(deleteTimeout time.Duration) Option {
return func(ctx context.Context, c *Driver) error {
c.tableOptions = append(c.tableOptions, tableConfig.WithDeleteTimeout(deleteTimeout))
c.queryOptions = append(c.queryOptions, queryConfig.WithSessionDeleteTimeout(deleteTimeout))
return nil
}
}
// WithSessionPoolKeepAliveMinSize set minimum sessions should be keeped alive in table.Client
//
// Deprecated: use WithApplicationName instead.
// Will be removed after Oct 2024.
// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
func WithSessionPoolKeepAliveMinSize(keepAliveMinSize int) Option {
return func(ctx context.Context, c *Driver) error { return nil }
}
// WithSessionPoolKeepAliveTimeout set timeout of keep alive requests for session in table.Client
//
// Deprecated: use WithApplicationName instead.
// Will be removed after Oct 2024.
// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
func WithSessionPoolKeepAliveTimeout(keepAliveTimeout time.Duration) Option {
return func(ctx context.Context, c *Driver) error { return nil }
}
// WithIgnoreTruncated disables errors on truncated flag
func WithIgnoreTruncated() Option {
return func(ctx context.Context, c *Driver) error {
c.tableOptions = append(c.tableOptions, tableConfig.WithIgnoreTruncated())
return nil
}
}
// WithPanicCallback specified behavior on panic
// Warning: WithPanicCallback must be defined on start of all options
// (before `WithTrace{Driver,Table,Scheme,Scripting,Coordination,Ratelimiter}` and other options)
// If not defined - panic would not intercept with driver
func WithPanicCallback(panicCallback func(e interface{})) Option {
return func(ctx context.Context, c *Driver) error {
c.panicCallback = panicCallback
c.options = append(c.options, config.WithPanicCallback(panicCallback))
return nil
}
}
// WithTraceTable appends trace.Table into table traces
func WithTraceTable(t trace.Table, opts ...trace.TableComposeOption) Option { //nolint:gocritic
return func(ctx context.Context, c *Driver) error {
c.tableOptions = append(
c.tableOptions,
tableConfig.WithTrace(
&t,
append(
[]trace.TableComposeOption{
trace.WithTablePanicCallback(c.panicCallback),
},
opts...,
)...,
),
)
return nil
}
}
// WithTraceQuery appends trace.Query into query traces
func WithTraceQuery(t trace.Query, opts ...trace.QueryComposeOption) Option { //nolint:gocritic
return func(ctx context.Context, c *Driver) error {
c.queryOptions = append(
c.queryOptions,
queryConfig.WithTrace(&t,
append(
[]trace.QueryComposeOption{
trace.WithQueryPanicCallback(c.panicCallback),
},
opts...,
)...,
),
)
return nil
}
}
// WithTraceScripting scripting trace option
func WithTraceScripting(t trace.Scripting, opts ...trace.ScriptingComposeOption) Option {
return func(ctx context.Context, c *Driver) error {
c.scriptingOptions = append(
c.scriptingOptions,
scriptingConfig.WithTrace(
t,
append(
[]trace.ScriptingComposeOption{
trace.WithScriptingPanicCallback(c.panicCallback),
},
opts...,
)...,
),
)
return nil
}
}
// WithTraceScheme returns scheme trace option
func WithTraceScheme(t trace.Scheme, opts ...trace.SchemeComposeOption) Option {
return func(ctx context.Context, c *Driver) error {
c.schemeOptions = append(
c.schemeOptions,
schemeConfig.WithTrace(
t,
append(
[]trace.SchemeComposeOption{
trace.WithSchemePanicCallback(c.panicCallback),
},
opts...,
)...,
),
)
return nil
}
}
// WithTraceCoordination returns coordination trace option
func WithTraceCoordination(t trace.Coordination, opts ...trace.CoordinationComposeOption) Option { //nolint:gocritic
return func(ctx context.Context, c *Driver) error {
c.coordinationOptions = append(
c.coordinationOptions,
coordinationConfig.WithTrace(
&t,
append(
[]trace.CoordinationComposeOption{
trace.WithCoordinationPanicCallback(c.panicCallback),
},
opts...,
)...,
),
)
return nil
}
}
// WithTraceRatelimiter returns ratelimiter trace option
func WithTraceRatelimiter(t trace.Ratelimiter, opts ...trace.RatelimiterComposeOption) Option {
return func(ctx context.Context, c *Driver) error {
c.ratelimiterOptions = append(
c.ratelimiterOptions,
ratelimiterConfig.WithTrace(
t,
append(
[]trace.RatelimiterComposeOption{
trace.WithRatelimiterPanicCallback(c.panicCallback),
},
opts...,
)...,
),
)
return nil
}
}
// WithRatelimiterOptions returns reatelimiter option
func WithRatelimiterOptions(opts ...ratelimiterConfig.Option) Option {
return func(ctx context.Context, c *Driver) error {
c.ratelimiterOptions = append(c.ratelimiterOptions, opts...)
return nil
}
}
// WithTraceDiscovery adds configured discovery tracer to Driver
func WithTraceDiscovery(t trace.Discovery, opts ...trace.DiscoveryComposeOption) Option {
return func(ctx context.Context, c *Driver) error {
c.discoveryOptions = append(
c.discoveryOptions,
discoveryConfig.WithTrace(
t,
append(
[]trace.DiscoveryComposeOption{
trace.WithDiscoveryPanicCallback(c.panicCallback),
},
opts...,
)...,
),
)
return nil
}
}
// WithTraceTopic adds configured discovery tracer to Driver
func WithTraceTopic(t trace.Topic, opts ...trace.TopicComposeOption) Option { //nolint:gocritic
return func(ctx context.Context, c *Driver) error {
c.topicOptions = append(
c.topicOptions,
topicoptions.WithTrace(
t,
append(
[]trace.TopicComposeOption{
trace.WithTopicPanicCallback(c.panicCallback),
},
opts...,
)...,
),
)
return nil
}
}
// WithTraceDatabaseSQL adds configured discovery tracer to Driver
func WithTraceDatabaseSQL(t trace.DatabaseSQL, opts ...trace.DatabaseSQLComposeOption) Option { //nolint:gocritic
return func(ctx context.Context, c *Driver) error {
c.databaseSQLOptions = append(
c.databaseSQLOptions,
xsql.WithTrace(
&t,
append(
[]trace.DatabaseSQLComposeOption{
trace.WithDatabaseSQLPanicCallback(c.panicCallback),
},
opts...,
)...,
),
)
return nil
}
}
// Private technical options for correct copies processing
func withOnClose(onClose func(c *Driver)) Option {
return func(ctx context.Context, c *Driver) error {
c.onClose = append(c.onClose, onClose)
return nil
}
}
func withConnPool(pool *conn.Pool) Option {
return func(ctx context.Context, c *Driver) error {
c.pool = pool
return pool.Take(ctx)
}
}