123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package canal
- import (
- "io/ioutil"
- "math/rand"
- "time"
- "github.com/BurntSushi/toml"
- "github.com/juju/errors"
- "github.com/siddontang/go-mysql/mysql"
- )
- type DumpConfig struct {
-
-
- ExecutionPath string `toml:"mysqldump"`
-
- Tables []string `toml:"tables"`
- TableDB string `toml:"table_db"`
- Databases []string `toml:"dbs"`
-
- IgnoreTables []string `toml:"ignore_tables"`
-
- DiscardErr bool `toml:"discard_err"`
-
-
- SkipMasterData bool `toml:"skip_master_data"`
-
- MaxAllowedPacketMB int `toml:"max_allowed_packet_mb"`
- }
- type Config struct {
- Addr string `toml:"addr"`
- User string `toml:"user"`
- Password string `toml:"password"`
- Charset string `toml:"charset"`
- ServerID uint32 `toml:"server_id"`
- Flavor string `toml:"flavor"`
- HeartbeatPeriod time.Duration `toml:"heartbeat_period"`
- ReadTimeout time.Duration `toml:"read_timeout"`
-
-
-
-
-
- IncludeTableRegex []string `toml:include_table_regex`
- ExcludeTableRegex []string `toml:exclude_table_regex`
-
- DiscardNoMetaRowEvent bool `toml:"discard_no_meta_row_event"`
- Dump DumpConfig `toml:"dump"`
- UseDecimal bool `toml:"use_decimal"`
- }
- func NewConfigWithFile(name string) (*Config, error) {
- data, err := ioutil.ReadFile(name)
- if err != nil {
- return nil, errors.Trace(err)
- }
- return NewConfig(string(data))
- }
- func NewConfig(data string) (*Config, error) {
- var c Config
- _, err := toml.Decode(data, &c)
- if err != nil {
- return nil, errors.Trace(err)
- }
- return &c, nil
- }
- func NewDefaultConfig() *Config {
- c := new(Config)
- c.Addr = "127.0.0.1:3306"
- c.User = "root"
- c.Password = ""
- c.Charset = mysql.DEFAULT_CHARSET
- rand.Seed(time.Now().Unix())
- c.ServerID = uint32(rand.Intn(1000)) + 1001
- c.Flavor = "mysql"
- c.Dump.ExecutionPath = "mysqldump"
- c.Dump.DiscardErr = true
- c.Dump.SkipMasterData = false
- return c
- }
|