forked from go-mysql-org/go-mysql-elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
52 lines (37 loc) · 899 Bytes
/
config.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
40
41
42
43
44
45
46
47
48
49
50
51
52
package river
import (
"io/ioutil"
"github.com/BurntSushi/toml"
)
type SourceConfig struct {
Schema string `toml:"schema"`
Tables []string `toml:"tables"`
}
type Config struct {
MyAddr string `toml:"my_addr"`
MyUser string `toml:"my_user"`
MyPassword string `toml:"my_pass"`
ESAddr string `toml:"es_addr"`
StatAddr string `toml:"stat_addr"`
ServerID uint32 `toml:"server_id"`
Flavor string `toml:"flavor"`
DataDir string `toml:"data_dir"`
DumpExec string `toml:"mysqldump"`
Sources []SourceConfig `toml:"source"`
Rules []*Rule `toml:"rule"`
}
func NewConfigWithFile(name string) (*Config, error) {
data, err := ioutil.ReadFile(name)
if err != nil {
return nil, err
}
return NewConfig(string(data))
}
func NewConfig(data string) (*Config, error) {
var c Config
_, err := toml.Decode(data, &c)
if err != nil {
return nil, err
}
return &c, nil
}