-
Notifications
You must be signed in to change notification settings - Fork 61
/
config.go
76 lines (71 loc) · 1.97 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
package config
import (
"github.com/BurntSushi/toml"
"github.com/sirupsen/logrus"
"strings"
)
var Logger *logrus.Entry
type Config struct {
Slack Settings
Mattermost Settings
Debug bool
Bind string
BindInterface string
BindPort int
TLSBind string
TLSDir string
Insecure bool
SkipTLSVerify bool
DefaultServer string
DefaultTeam string
Restrict string
JoinExclude []string
JoinInclude []string
PartFake bool
}
type Settings struct {
BlackListUser []string
DefaultServer string
DefaultTeam string
Insecure bool
JoinExclude []string
JoinInclude []string
JoinMpImOnTalk bool
PartFake bool
Restrict []string
SkipTLSVerify bool
UseDisplayName bool
PrefixMainTeam bool
}
func LoadConfig(cfgfile string, defaultcfg Config) *Config {
if _, err := toml.DecodeFile(cfgfile, &defaultcfg); err != nil {
Logger.Fatalf("Error loading config file %s: %s", cfgfile, err)
}
Logger.Infof("Loaded config from %s", cfgfile)
// migratie mattermost specific settings from general to mattermost settings
if len(defaultcfg.Mattermost.JoinInclude) == 0 {
defaultcfg.Mattermost.JoinInclude = defaultcfg.JoinInclude
}
if len(defaultcfg.Mattermost.JoinExclude) == 0 {
defaultcfg.Mattermost.JoinExclude = defaultcfg.JoinExclude
}
if !defaultcfg.Mattermost.PartFake {
defaultcfg.Mattermost.PartFake = defaultcfg.PartFake
}
if len(defaultcfg.Mattermost.Restrict) == 0 {
defaultcfg.Mattermost.Restrict = strings.Fields(defaultcfg.Restrict)
}
if defaultcfg.Mattermost.DefaultServer == "" {
defaultcfg.Mattermost.DefaultServer = defaultcfg.DefaultServer
}
if defaultcfg.Mattermost.DefaultTeam == "" {
defaultcfg.Mattermost.DefaultTeam = defaultcfg.DefaultTeam
}
if !defaultcfg.Mattermost.Insecure {
defaultcfg.Mattermost.Insecure = defaultcfg.Insecure
}
if !defaultcfg.Mattermost.SkipTLSVerify {
defaultcfg.Mattermost.SkipTLSVerify = defaultcfg.SkipTLSVerify
}
return &defaultcfg
}