-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
61 lines (50 loc) · 1.01 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
package rpc
import (
"google.golang.org/grpc"
"sync"
"time"
)
type chanStat = bool
type Pool struct {
ServerAddr string
MaxCap int64
AcquireTimeout time.Duration
DynamicLink bool
OverflowCap bool
dialOptions []grpc.DialOption
lock *sync.Mutex
connections chan *grpc.ClientConn
ChannelStat chanStat
counter int64
}
type Option func(*Pool)
func WithMaxCap(num int64) Option {
return func(pool *Pool) {
pool.MaxCap = num
}
}
func WithServerAddr(addr string) Option {
return func(pool *Pool) {
pool.ServerAddr = addr
}
}
func WithAcquireTimeOut(timeout time.Duration) Option {
return func(pool *Pool) {
pool.AcquireTimeout = timeout
}
}
func WithOverflowCap(overflowCap bool) Option {
return func(pool *Pool) {
pool.OverflowCap = overflowCap
}
}
func WithDynamicLink(dynamicLink bool) Option {
return func(pool *Pool) {
pool.DynamicLink = dynamicLink
}
}
func WithDialOption(ops ...grpc.DialOption) Option {
return func(pool *Pool) {
pool.dialOptions = ops
}
}