Skip to content

Commit 63108f6

Browse files
authored
Merge pull request #516 from gaojijun/master
2 parents 8801d83 + 4dd640d commit 63108f6

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

README.md

+25-13
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,18 @@ You must use ROW format for binlog, full binlog row image is preferred, because
120120
A simple example:
121121

122122
```go
123-
cfg := NewDefaultConfig()
124-
cfg.Addr = "127.0.0.1:3306"
125-
cfg.User = "root"
126-
// We only care table canal_test in test db
127-
cfg.Dump.TableDB = "test"
128-
cfg.Dump.Tables = []string{"canal_test"}
123+
package main
129124

130-
c, err := NewCanal(cfg)
125+
import (
126+
"github.com/siddontang/go-log/log"
127+
"github.com/siddontang/go-mysql/canal"
128+
)
131129

132130
type MyEventHandler struct {
133-
DummyEventHandler
131+
canal.DummyEventHandler
134132
}
135133

136-
func (h *MyEventHandler) OnRow(e *RowsEvent) error {
134+
func (h *MyEventHandler) OnRow(e *canal.RowsEvent) error {
137135
log.Infof("%s %v\n", e.Action, e.Rows)
138136
return nil
139137
}
@@ -142,11 +140,25 @@ func (h *MyEventHandler) String() string {
142140
return "MyEventHandler"
143141
}
144142

145-
// Register a handler to handle RowsEvent
146-
c.SetEventHandler(&MyEventHandler{})
143+
func main() {
144+
cfg := canal.NewDefaultConfig()
145+
cfg.Addr = "127.0.0.1:3306"
146+
cfg.User = "root"
147+
// We only care table canal_test in test db
148+
cfg.Dump.TableDB = "test"
149+
cfg.Dump.Tables = []string{"canal_test"}
150+
151+
c, err := canal.NewCanal(cfg)
152+
if err != nil {
153+
log.Fatal(err)
154+
}
155+
156+
// Register a handler to handle RowsEvent
157+
c.SetEventHandler(&MyEventHandler{})
147158

148-
// Start canal
149-
c.Run()
159+
// Start canal
160+
c.Run()
161+
}
150162
```
151163

152164
You can see [go-mysql-elasticsearch](https://github.com/siddontang/go-mysql-elasticsearch) for how to sync MySQL data into Elasticsearch.

0 commit comments

Comments
 (0)