-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathpool_options.go
60 lines (49 loc) · 1.3 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
package client
import (
"time"
)
type (
poolOptions struct {
logFunc LogFunc
minAlive int
maxAlive int
maxIdle int
addr string
user string
password string
dbName string
connOptions []func(conn *Conn)
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 WithLogFunc(f LogFunc) PoolOption {
return func(o *poolOptions) {
o.logFunc = f
}
}
func WithConnOptions(options ...func(conn *Conn)) 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
}
}