-
Notifications
You must be signed in to change notification settings - Fork 1
/
gomaxscale_options.go
107 lines (94 loc) · 2.27 KB
/
gomaxscale_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
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
103
104
105
106
107
package gomaxscale
import (
"log"
"time"
)
// Options stores all available options to connect with MaxScale.
type Options struct {
auth struct {
user string
password string
}
timeouts struct {
timeRef func() time.Time
read time.Duration
write time.Duration
}
stats struct {
period time.Duration
ticker func(Stats)
}
uuid string
version *int
gtid string // Requested GTID position
bufferSize int
logger logger
}
// Option is a function that can be used to configure the library.
type Option func(*Options)
func newDefaultOptions() Options {
var opts Options
opts.uuid = "XXX-YYY_YYY"
opts.timeouts.read = 2 * time.Second
opts.timeouts.write = 2 * time.Second
opts.timeouts.timeRef = time.Now
opts.bufferSize = 4096
opts.logger = log.Default()
return opts
}
// WithAuth sets the authentication options.
func WithAuth(user, password string) Option {
return func(o *Options) {
o.auth.user = user
o.auth.password = password
}
}
// WithGTID sets the GTID position.
func WithGTID(gtid string) Option {
return func(o *Options) {
o.gtid = gtid
}
}
// WithTimeout sets connection timeouts.
func WithTimeout(readTimeout, writeTimeout time.Duration) Option {
return func(o *Options) {
o.timeouts.read = readTimeout
o.timeouts.write = writeTimeout
}
}
// WithStats enables statistics in the library. The ticker callback is called
// every period of time with information about events and processing time.
func WithStats(period time.Duration, ticker func(Stats)) Option {
return func(o *Options) {
o.stats.period = period
o.stats.ticker = ticker
}
}
// WithUUID sets the UUID of the client.
func WithUUID(uuid string) Option {
return func(o *Options) {
o.uuid = uuid
}
}
// WithVersion sets the binlog version to use.
func WithVersion(version int) Option {
return func(o *Options) {
o.version = &version
}
}
// WithBufferSize sets the buffer size for the data stream.
func WithBufferSize(bufferSize int) Option {
return func(o *Options) {
o.bufferSize = bufferSize
}
}
// WithLogger sets the logger to report issues when processing the data stream.
func WithLogger(logger logger) Option {
return func(o *Options) {
o.logger = logger
}
}
type logger interface {
Print(v ...interface{})
Printf(format string, v ...interface{})
}