-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.go
39 lines (34 loc) · 926 Bytes
/
hook.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
package main
import (
"github.com/enustah/db-canal/driver"
"github.com/enustah/db-canal/hook"
"github.com/enustah/db-canal/register"
"github.com/enustah/db-canal/util"
)
func init() {
util.Must(
register.RegisterHook(
func(ctx *hook.Ctx, args []interface{}) error {
// drop indicate the data will drop
// stop indicate stop iterate
ctx.ForEach(func(data *driver.Data) (drop bool, stop bool) {
// do sth with data
return
})
// like gin middleware, ctx.Next() will run next hook
// ctx.Next()
// ctx.Abort() will stop the hook
// ctx.Abort()
// return error will retry whole hook chain.
// don't return error as much as possible.
// and must not return permanent error.
return nil
},
"hook1",
[]hook.Arg{hook.ArgTypeStr, hook.ArgTypeFloat, hook.ArgTypeInt},
// option args validate
// func(args []interface{}) error {
//
// },
))
}