/
option.go
47 lines (38 loc) · 1015 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
package prophet
import (
"time"
"github.com/deepfabric/prophet/codec"
"github.com/deepfabric/prophet/pb/metapb"
"github.com/deepfabric/prophet/util"
"github.com/fagongzi/goetty"
"github.com/fagongzi/goetty/buf"
)
// Option client option
type Option func(*options)
type options struct {
leaderGetter func() *metapb.Member
rpcTimeout time.Duration
}
func (opts *options) adjust() {
if opts.rpcTimeout == 0 {
opts.rpcTimeout = time.Second * 10
}
}
// WithLeaderGetter set a func to get a leader
func WithLeaderGetter(value func() *metapb.Member) Option {
return func(opts *options) {
opts.leaderGetter = value
}
}
// WithRPCTimeout set rpc timeout
func WithRPCTimeout(value time.Duration) Option {
return func(opts *options) {
opts.rpcTimeout = value
}
}
func createConn() goetty.IOSession {
encoder, decoder := codec.NewClientCodec(10 * buf.MB)
return goetty.NewIOSession(goetty.WithCodec(encoder, decoder),
goetty.WithLogger(util.GetLogger()),
goetty.WithEnableAsyncWrite(16))
}