diff options
author | Wim <wim@42.be> | 2018-03-04 23:52:14 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2018-03-04 23:52:14 +0100 |
commit | f2f1d874e1b4f997c111de87121eec98eef66381 (patch) | |
tree | 34a44e866c053ef298d5482370208a0bb9dc4738 /bridge/bridge.go | |
parent | 25a72113b122f984c904b24c4af23a1cba1eff45 (diff) | |
download | matterbridge-msglm-f2f1d874e1b4f997c111de87121eec98eef66381.tar.gz matterbridge-msglm-f2f1d874e1b4f997c111de87121eec98eef66381.tar.bz2 matterbridge-msglm-f2f1d874e1b4f997c111de87121eec98eef66381.zip |
Use viper (github.com/spf13/viper) for configuration
Diffstat (limited to 'bridge/bridge.go')
-rw-r--r-- | bridge/bridge.go | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/bridge/bridge.go b/bridge/bridge.go index 93e1cd8f..8135cabf 100644 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -15,7 +15,6 @@ type Bridger interface { } type Bridge struct { - Config config.Protocol Bridger Name string Account string @@ -23,10 +22,19 @@ type Bridge struct { Channels map[string]config.ChannelInfo Joined map[string]bool Log *log.Entry + Config *config.Config + General *config.Protocol +} + +type Config struct { + // General *config.Protocol + Remote chan config.Message + Log *log.Entry + *Bridge } // Factory is the factory function to create a bridge -type Factory func(*config.BridgeConfig) Bridger +type Factory func(*Config) Bridger func New(bridge *config.Bridge) *Bridge { b := new(Bridge) @@ -59,3 +67,42 @@ func (b *Bridge) joinChannels(channels map[string]config.ChannelInfo, exists map } return nil } + +func (b *Bridge) ReloadConfig() { + return +} + +func (b *Bridge) GetBool(key string) bool { + if b.Config.GetBool(b.Account+"."+key) != false { + return b.Config.GetBool(b.Account + "." + key) + } + return b.Config.GetBool("general." + key) +} + +func (b *Bridge) GetInt(key string) int { + if b.Config.GetInt(b.Account+"."+key) != 0 { + return b.Config.GetInt(b.Account + "." + key) + } + return b.Config.GetInt("general." + key) +} + +func (b *Bridge) GetString(key string) string { + if b.Config.GetString(b.Account+"."+key) != "" { + return b.Config.GetString(b.Account + "." + key) + } + return b.Config.GetString("general." + key) +} + +func (b *Bridge) GetStringSlice(key string) []string { + if len(b.Config.GetStringSlice(b.Account+"."+key)) != 0 { + return b.Config.GetStringSlice(b.Account + "." + key) + } + return b.Config.GetStringSlice("general." + key) +} + +func (b *Bridge) GetStringSlice2D(key string) [][]string { + if len(b.Config.GetStringSlice2D(b.Account+"."+key)) != 0 { + return b.Config.GetStringSlice2D(b.Account + "." + key) + } + return b.Config.GetStringSlice2D("general." + key) +} |