-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
51 lines (44 loc) · 797 Bytes
/
option.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
package txmng
import (
"time"
)
type Option func(cfg *Config)
type Config struct {
forbidRawDB bool
retries *retries
}
type retries struct {
count int
interval time.Duration
need func(error) bool
}
func WithForbidRawDB(v bool) Option {
return func(cfg *Config) {
cfg.forbidRawDB = v
}
}
func WithRetries(
retryCount int,
retryInterval time.Duration,
retryNeed func(error) bool,
) Option {
return func(cfg *Config) {
cfg.retries = &retries{
count: retryCount,
interval: retryInterval,
need: retryNeed,
}
}
}
func WithDefaultRetries(
retryCount int,
retryInterval time.Duration,
) Option {
return func(cfg *Config) {
cfg.retries = &retries{
count: retryCount,
interval: retryInterval,
need: isPGXSerializationError,
}
}
}