You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
910 B
39 lines
910 B
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
|
|
}
|
|
|