1
0
Fork 0
bocadillo/README.md

47 lines
1.1 KiB
Markdown
Raw Normal View History

2018-11-11 15:13:33 +00:00
# Bocadillo
Bocadillo is a parser for MySQL binary log. It can connect to a server, register
as a slave and process binary log.
### Usage
```go
// import "github.com/localhots/bocadillo/reader"
2018-11-11 15:17:41 +00:00
// import "github.com/localhots/bocadillo/reader/slave"
2018-11-11 15:13:33 +00:00
reader, _ := reader.New("root@(127.0.0.1:3306)/testdb", slave.Config{
2018-11-11 15:16:08 +00:00
ServerID: 1000, // Arbitrary unique ID
2018-11-11 15:13:33 +00:00
File: "mysql-bin.000035", // Log file name
Offset: 4, // Log file offset
})
for {
evt, err := reader.ReadEvent()
if err != nil {
log.Fatalf("Failed to read event: %v", err)
2018-11-11 15:17:41 +00:00
}
2018-11-11 15:13:33 +00:00
log.Println("Event received:", evt.Header.Type.String())
if evt.Table != nil {
rows, err := evt.DecodeRows()
if err != nil {
log.Fatalf("Failed to parse rows event: %v", err)
2018-11-11 15:17:41 +00:00
}
log.Println("Table:", evt.Table.TableName, "Changes:", rows.Rows)
}
2018-11-11 15:13:33 +00:00
}
```
2018-07-29 17:20:30 +00:00
### WIP
2018-11-11 15:16:08 +00:00
This package is a work in progress and can't be considered production ready just
yet.
A fork of [go-sql-driver/mysql](https://github.com/localhots/mysql) is used
2018-07-29 17:22:40 +00:00
to provide underlying connection and basic packet exchange.
2018-07-29 17:20:30 +00:00
### Licence
2018-07-29 17:24:25 +00:00
MIT