-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconfig.go
78 lines (61 loc) · 2.42 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package warppipe
import (
"errors"
"fmt"
"github.com/kelseyhightower/envconfig"
"github.com/sirupsen/logrus"
)
// DBConfig represents the database configuration settings.
type DBConfig struct {
Host string `envconfig:"DB_HOST"`
Port int `envconfig:"DB_PORT"`
User string `envconfig:"DB_USER"`
Password string `envconfig:"DB_PASS"`
Database string `envconfig:"DB_NAME"`
Schema string `envconfig:"DB_SCHEMA"`
}
// Config represents the warp pipe configuration settings.
type Config struct {
// Database connection settings.
Database DBConfig
// If defined, warppipe will only emit changes for the specified tables.
WhitelistTables []string `envconfig:"WHITELIST_TABLES"`
// If set, warppipe will suppress changes for any specified tables.
// Note: This setting takes precedent over the whitelisted tables.
IgnoreTables []string `envconfig:"IGNORE_TABLES"`
// Replication mode may be either `lr` (logical replication) or `audit`.
ReplicationMode string `envconfig:"REPLICATION_MODE" default:"lr"`
// Specifies the replication slot name to be used. (LR mode only)
ReplicationSlotName string `envconfig:"REPLICATION_SLOT_NAME"`
// Start replication from the specified logical sequence number. (LR mode only)
StartFromLSN uint64 `envconfig:"START_FROM_LSN"`
// Start replication from the specified changeset ID. (Audit mode only)
StartFromID int64 `envconfig:"START_FROM_ID"`
// Start replication from the specified changeset timestamp. (Audit mode only)
StartFromTimestamp int64 `envconfig:"START_FROM_TIMESTAMP"`
// Sets the log level
LogLevel string `envconfig:"LOG_LEVEL" default:"info"`
}
// NewConfigFromEnv returns a new Config initialized with values read from the environment.
func NewConfigFromEnv() (*Config, error) {
var c Config
err := envconfig.Process("wp", &c)
if err != nil {
return nil, errors.New("unable to parse configuration from environment")
}
var dbCfg DBConfig
err = envconfig.Process("wp", &dbCfg)
if err != nil {
return nil, errors.New("unable to parse database configuration from environment")
}
c.Database = dbCfg
return &c, nil
}
// ParseLogLevel parses a log level string and returns a logrus.Level.
func ParseLogLevel(level string) (logrus.Level, error) {
lvl, err := logrus.ParseLevel(level)
if err != nil {
return 0, fmt.Errorf("Error: '%s' is not a valid log level. Must be one of: 'trace', 'debug', 'info', 'warn', 'error', 'fatal'", level)
}
return lvl, err
}