1
0
Fork 0
bocadillo/README.md

64 lines
1.9 KiB
Markdown
Raw Permalink Normal View History

2018-11-11 15:13:33 +00:00
# Bocadillo
2019-10-28 19:41:19 +00:00
Bocadillo is a client for MySQL binary log. It is not a complete solution (yet).
2018-11-11 15:13:33 +00:00
### Usage
2019-10-28 19:41:19 +00:00
Example use:
2018-11-11 15:13:33 +00:00
```go
// import "github.com/localhots/bocadillo/reader"
2019-10-28 19:41:19 +00:00
// import "github.com/localhots/bocadillo/reader/driver"
2018-11-11 15:13:33 +00:00
2019-10-28 19:41:19 +00:00
reader, err := reader.New("root@(127.0.0.1:3306)/testdb", driver.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
})
2019-10-28 19:41:19 +00:00
if err != nil {
log.Fatalf("Failed to connect: %v", err)
}
2018-11-11 15:13:33 +00:00
for {
evt, err := reader.ReadEvent()
if err != nil {
log.Fatalf("Failed to read event: %v", err)
2018-11-11 15:17:41 +00:00
}
2019-10-28 19:41:19 +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
2019-10-28 19:41:19 +00:00
### Caveats
This library is not a complete solution. It requires implementation that would
involve everything from configuration to state management. Future releases
might include pre-made binaries for certain message queue adapters.
2018-07-29 17:20:30 +00:00
2019-10-28 19:41:19 +00:00
### Future development & contributions
2018-11-11 15:16:08 +00:00
2019-10-28 19:41:19 +00:00
The package in its current state does the job for me. Bug reports are welcome
just like feature contributions.
### Go MySQL driver modifications
Modified copy of [go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)
is included with this project. It was changed in order to expose certain low
2020-07-27 22:12:19 +00:00
level functions that allow to establish a connection manually and register as a
replica server and to remove automatic driver registration because it will
likely conflict with the original code when imported as a dependency.
2018-07-29 17:22:40 +00:00
2018-07-29 17:20:30 +00:00
### Licence
2019-10-28 19:41:19 +00:00
Mozilla Public License Version 2.0
This project includes a modified copy of [go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)
which is licensed under MPL-2.0, hence it should be licensed under the same
lincense (or a GPL one).