package config import "github.com/go-mysql-org/go-mysql/canal" type Config struct { MySQL struct { Addr string `yaml:"addr"` User string `yaml:"user"` Password string `yaml:"password"` Database string `yaml:"database"` } `yaml:"mysql"` Sync struct { Tables []string `yaml:"tables"` BatchSize int `yaml:"batch_size"` Workers int `yaml:"workers"` } `yaml:"sync"` Storage struct { Type string `yaml:"type"` // memory, redis, file FilePath string `yaml:"file_path"` RedisURL string `yaml:"redis_url"` } `yaml:"storage"` } func (c *Config) ToCanalConfig() *canal.Config { cfg := canal.NewDefaultConfig() cfg.Addr = c.MySQL.Addr cfg.User = c.MySQL.User cfg.Password = c.MySQL.Password cfg.Dump.ExecutionPath = "" // 只监听指定数据库 if c.MySQL.Database != "" { cfg.IncludeTableRegex = []string{c.MySQL.Database + "\\..*"} } return cfg }