commit 0240c70f3e3e28c8666eca3cfe6a1abb309dc81b
Author: Wim <wim@42.be>
Date: Mon Mar 05 00:30:46 2018 +0000
diff --git a/bridge/bridge.go b/bridge/bridge.go
index 8135cab..0436eeb 100644
--- a/bridge/bridge.go
+++ b/bridge/bridge.go
@@ -6812 +688 @@ 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 {
+ if b.Config.GetBool(b.Account + "." + key) {
return b.Config.GetBool(b.Account + "." + key)
}
return b.Config.GetBool("general." + key)
diff --git a/bridge/config/config.go b/bridge/config/config.go
index a89f9aa..42a87f1 100644
--- a/bridge/config/config.go
+++ b/bridge/config/config.go
@@ -16 +17 @@
package config
import (
+ "bytes"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"os"
@@ -1926 +19323 @@ func NewConfig(cfgfile string) *Config {
return mycfg
}
+func NewConfigFromString(input []byte) *Config {
+ var cfg ConfigValues
+ viper.SetConfigType("toml")
+ err := viper.ReadConfig(bytes.NewBuffer(input))
+ if err != nil {
+ log.Fatal(err)
+ }
+ err = viper.Unmarshal(&cfg)
+ if err != nil {
+ log.Fatal(err)
+ }
+ mycfg := new(Config)
+ mycfg.v = viper.GetViper()
+ mycfg.ConfigValues = &cfg
+ return mycfg
+}
+
func (c *Config) GetBool(key string) bool {
c.RLock()
defer c.RUnlock()
diff --git a/gateway/gateway.go b/gateway/gateway.go
index a637dcf..694fa95 100644
--- a/gateway/gateway.go
+++ b/gateway/gateway.go
@@ -237 +236 @@ import (
"github.com/hashicorp/golang-lru"
"github.com/peterhellberg/emojilib"
"net/http"
- "reflect"
"regexp"
"strings"
"time"
@@ -45014 +4496 @@ func getChannelID(msg config.Message) string {
return msg.Channel + msg.Account
}
-//getField returns the Protocol configuration for a specific protocol (field)
-func getField(cfg *config.Config, field string) map[string]config.Protocol {
- r := reflect.ValueOf(cfg)
- f := reflect.Indirect(r).FieldByName(field)
- i := f.Interface()
- return i.(map[string]config.Protocol)
-}
-
func isApi(account string) bool {
return strings.HasPrefix(account, "api.")
}
diff --git a/gateway/gateway_test.go b/gateway/gateway_test.go
index 76faa89..2524217 100644
--- a/gateway/gateway_test.go
+++ b/gateway/gateway_test.go
@@ -314 +313 @@ package gateway
import (
"fmt"
"github.com/42wim/matterbridge/bridge/config"
- "github.com/BurntSushi/toml"
"github.com/stretchr/testify/assert"
"strconv"
"testing"
)
-var testconfig = `
+var testconfig = []byte(`
[irc.freenode]
[mattermost.test]
[gitter.42wim]
@@ -379 +369 @@ var testconfig = `
- `
+ `)
-var testconfig2 = `
+var testconfig2 = []byte(`
[irc.freenode]
[mattermost.test]
[gitter.42wim]
@@ -808 +799 @@ var testconfig2 = `
- `
-var testconfig3 = `
+ `)
+
+var testconfig3 = []byte(`
[irc.zzz]
[telegram.zzz]
[slack.zzz]
@@ -14913 +14910 @@ enable=true
-`
+`)
-func maketestRouter(input string) *Router {
- var cfg *config.Config
- if _, err := toml.Decode(input, &cfg); err != nil {
- fmt.Println(err)
- }
+func maketestRouter(input []byte) *Router {
+ cfg := config.NewConfigFromString(input)
r, err := NewRouter(cfg)
if err != nil {
fmt.Println(err)
@@ -16314 +1607 @@ func maketestRouter(input string) *Router {
return r
}
func TestNewRouter(t *testing.T) {
- var cfg *config.Config
- if _, err := toml.Decode(testconfig, &cfg); err != nil {
- fmt.Println(err)
- }
- r, err := NewRouter(cfg)
- if err != nil {
- fmt.Println(err)
- }
+ r := maketestRouter(testconfig)
assert.Equal(t, 1, len(r.Gateways))
assert.Equal(t, 4, len(r.Gateways["bridge1"].Bridges))
assert.Equal(t, 4, len(r.Gateways["bridge1"].Channels))