-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathpool_options.go
61 lines (50 loc) · 1.31 KB
/
pool_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
package client
import (
"log/slog"
"time"
)
type (
poolOptions struct {
logger *slog.Logger
minAlive int
maxAlive int
maxIdle int
addr string
user string
password string
dbName string
connOptions []Option
newPoolPingTimeout time.Duration
}
)
type (
PoolOption func(o *poolOptions)
)
// WithPoolLimits sets pool limits:
// - minAlive specifies the minimum number of open connections that the pool will try to maintain.
// - maxAlive specifies the maximum number of open connections (for internal reasons,
// may be greater by 1 inside newConnectionProducer).
// - maxIdle specifies the maximum number of idle connections (see DefaultIdleTimeout).
func WithPoolLimits(minAlive, maxAlive, maxIdle int) PoolOption {
return func(o *poolOptions) {
o.minAlive = minAlive
o.maxAlive = maxAlive
o.maxIdle = maxIdle
}
}
func WithLogger(logger *slog.Logger) PoolOption {
return func(o *poolOptions) {
o.logger = logger
}
}
func WithConnOptions(options ...Option) PoolOption {
return func(o *poolOptions) {
o.connOptions = append(o.connOptions, options...)
}
}
// WithNewPoolPingTimeout enables connect & ping to DB during the pool initialization
func WithNewPoolPingTimeout(timeout time.Duration) PoolOption {
return func(o *poolOptions) {
o.newPoolPingTimeout = timeout
}
}