summaryrefslogtreecommitdiffstats
path: root/bridge/bridge.go
diff options
context:
space:
mode:
authorDuco van Amstel <duco.vanamstel@gmail.com>2018-11-13 22:30:56 +0000
committerWim <wim@42.be>2018-11-13 23:30:56 +0100
commit16d5aeac7c2de010d30cddc90c5755ac5b989b2b (patch)
tree9d95ee605be7d287e49212053ac19f88842133a8 /bridge/bridge.go
parente19ba5a06ad94c389df1b253d30c9ba6e4d14273 (diff)
downloadmatterbridge-msglm-16d5aeac7c2de010d30cddc90c5755ac5b989b2b.tar.gz
matterbridge-msglm-16d5aeac7c2de010d30cddc90c5755ac5b989b2b.tar.bz2
matterbridge-msglm-16d5aeac7c2de010d30cddc90c5755ac5b989b2b.zip
Make config.Config more unit-test friendly (#586)
Diffstat (limited to 'bridge/bridge.go')
-rw-r--r--bridge/bridge.go37
1 files changed, 21 insertions, 16 deletions
diff --git a/bridge/bridge.go b/bridge/bridge.go
index 0436eeb6..debe2d62 100644
--- a/bridge/bridge.go
+++ b/bridge/bridge.go
@@ -22,7 +22,7 @@ type Bridge struct {
Channels map[string]config.ChannelInfo
Joined map[string]bool
Log *log.Entry
- Config *config.Config
+ Config config.Config
General *config.Protocol
}
@@ -69,36 +69,41 @@ func (b *Bridge) joinChannels(channels map[string]config.ChannelInfo, exists map
}
func (b *Bridge) GetBool(key string) bool {
- if b.Config.GetBool(b.Account + "." + key) {
- return b.Config.GetBool(b.Account + "." + key)
+ val, ok := b.Config.GetBool(b.Account + "." + key)
+ if !ok {
+ val, _ = b.Config.GetBool("general." + key)
}
- return b.Config.GetBool("general." + key)
+ return val
}
func (b *Bridge) GetInt(key string) int {
- if b.Config.GetInt(b.Account+"."+key) != 0 {
- return b.Config.GetInt(b.Account + "." + key)
+ val, ok := b.Config.GetInt(b.Account + "." + key)
+ if !ok {
+ val, _ = b.Config.GetInt("general." + key)
}
- return b.Config.GetInt("general." + key)
+ return val
}
func (b *Bridge) GetString(key string) string {
- if b.Config.GetString(b.Account+"."+key) != "" {
- return b.Config.GetString(b.Account + "." + key)
+ val, ok := b.Config.GetString(b.Account + "." + key)
+ if !ok {
+ val, _ = b.Config.GetString("general." + key)
}
- return b.Config.GetString("general." + key)
+ return val
}
func (b *Bridge) GetStringSlice(key string) []string {
- if len(b.Config.GetStringSlice(b.Account+"."+key)) != 0 {
- return b.Config.GetStringSlice(b.Account + "." + key)
+ val, ok := b.Config.GetStringSlice(b.Account + "." + key)
+ if !ok {
+ val, _ = b.Config.GetStringSlice("general." + key)
}
- return b.Config.GetStringSlice("general." + key)
+ return val
}
func (b *Bridge) GetStringSlice2D(key string) [][]string {
- if len(b.Config.GetStringSlice2D(b.Account+"."+key)) != 0 {
- return b.Config.GetStringSlice2D(b.Account + "." + key)
+ val, ok := b.Config.GetStringSlice2D(b.Account + "." + key)
+ if !ok {
+ val, _ = b.Config.GetStringSlice2D("general." + key)
}
- return b.Config.GetStringSlice2D("general." + key)
+ return val
}