-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
41 lines (35 loc) · 851 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
package main
import (
"os"
"strings"
)
const (
DBConnString = "DB_CONN"
DBCanalAddr = "DB_CANAL_ADDR"
DBCanalUser = "DB_CANAL_USER"
DBCanalPassword = "DB_CANAL_PASSWORD"
DBCanalTableRegex = "DB_CANAL_TABLE_REGEX"
)
type Config struct {
ConnString string
CanalAddr string
CanalUser string
CanalPassword string
CanalTableRegex []string
}
func loadConfig() Config {
return Config{
ConnString: envStr(DBConnString, "root:@tcp(127.0.0.1:3306)/binl"),
CanalAddr: envStr(DBCanalAddr, "localhost:3306"),
CanalUser: envStr(DBCanalUser, "root"),
CanalPassword: envStr(DBCanalPassword, ""),
CanalTableRegex: strings.Split(envStr(DBCanalTableRegex, "binl*"), ","),
}
}
func envStr(n, def string) string {
str := os.Getenv(n)
if len(str) == 0 {
return def
}
return str
}