-
Notifications
You must be signed in to change notification settings - Fork 1
/
reader.go
43 lines (37 loc) · 1.04 KB
/
reader.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
package main
import (
"fmt"
"github.com/siddontang/go-mysql/mysql"
"github.com/siddontang/go-mysql/replication"
)
type BinlogReader struct {
Config replication.BinlogSyncerConfig
GTID mysql.GTIDSet
Syncer *replication.BinlogSyncer
}
func NewBinlogReader() (binlogReader *BinlogReader, err error) {
binlogReader = &BinlogReader{
Config: replication.BinlogSyncerConfig{
Flavor: "mysql",
Host: Config.MySQL.Host,
Port: Config.MySQL.Port,
User: Config.MySQL.User,
Password: Config.MySQL.Password,
ServerID: Config.MySQL.ServerID,
Localhost: "proxysql_binlog",
},
}
gtid, err := Config.getMasterGTIDSet()
if err != nil {
return nil, fmt.Errorf("unable to get MySQL executed GTIDs: %v", err)
}
binlogReader.GTID = gtid
binlogReader.Syncer = replication.NewBinlogSyncer(binlogReader.Config)
return binlogReader, nil
}
func (r *BinlogReader) StartSync() (binlogStreamer *replication.BinlogStreamer, err error) {
return r.Syncer.StartSyncGTID(r.GTID)
}
func (r *BinlogReader) Close() {
r.Syncer.Close()
}