-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoption.go
102 lines (83 loc) · 1.76 KB
/
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
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
package pool
import (
"context"
"io"
"net"
"time"
)
type DialFunc func(context.Context) (net.Conn, error)
type ReadFunc func(conn net.Conn) error
type WriteFunc func(p []byte) func(w io.Writer) error
type ReceiveHandler func(context.Context, []byte)
type KeepAliveFunc func(conn net.Conn)
type Option func(o *Options)
type Options struct {
Dialer DialFunc
OnClose func(*Conn) error
ReceiveHandler ReceiveHandler
ReadFunc ReadFunc
Keepalive KeepAliveFunc
WriteFunc WriteFunc
PoolFIFO bool
PoolSize int
MinIdleConns int
MaxConnAge time.Duration
PoolTimeout time.Duration
IdleTimeout time.Duration
IdleCheckFrequency time.Duration
}
func WithReadFunc(fn ReadFunc) Option {
return func(o *Options) {
o.ReadFunc = fn
}
}
func WithWriteFunc(fn WriteFunc) Option {
return func(o *Options) {
o.WriteFunc = fn
}
}
func WithKeepAlive(fn KeepAliveFunc) Option {
return func(o *Options) {
o.Keepalive = fn
}
}
func WithReceiveHandle(fn ReceiveHandler) Option {
return func(o *Options) {
o.ReceiveHandler = fn
}
}
func WithPoolFIFO(b bool) Option {
return func(o *Options) {
o.PoolFIFO = b
}
}
func WithPoolSize(i int) Option {
return func(o *Options) {
o.PoolSize = i
}
}
func WithMinIdleConns(i int) Option {
return func(o *Options) {
o.MinIdleConns = i
}
}
func WithMaxConnAge(d time.Duration) Option {
return func(o *Options) {
o.MaxConnAge = d
}
}
func WithPoolTimeout(d time.Duration) Option {
return func(o *Options) {
o.PoolTimeout = d
}
}
func WithIdleTimeout(d time.Duration) Option {
return func(o *Options) {
o.IdleTimeout = d
}
}
func WithIdleCheckFrequency(d time.Duration) Option {
return func(o *Options) {
o.IdleCheckFrequency = d
}
}