-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
54 lines (48 loc) · 1.26 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
package main
import (
"github.com/juju/loggo"
"github.com/micro/go-micro/config"
"github.com/micro/go-micro/config/source/env"
"github.com/micro/go-micro/config/source/file"
"slack-bot/workers"
"strings"
)
type logger struct {
Level string
}
type slackConfig struct {
Token string `json:"token"`
ExcludedUsers []string `json:"excluded_user_ids"`
}
type Configuration struct{
Loggers map[string]logger `json:"loggers"`
Slack slackConfig `json:"slack"`
Workers []workers.Config `json:"workers"`
}
func loggerConfigInitiator(conf *map[string]logger){
var configLoggers []string
for name, logger := range *conf {
configLoggers = append(configLoggers, name+"="+logger.Level)
}
err := loggo.ConfigureLoggers(strings.Join(configLoggers,";"))
if err != nil {}
}
func configConstructor() Configuration {
var conf Configuration
loadConfigErr := config.Load(
env.NewSource(
env.WithStrippedPrefix("SB"),
),
file.NewSource(
file.WithPath("slack-bot.yaml"),
file.WithPath("slack-bot-template.yaml"),
),
)
if loadConfigErr != nil { }
syncConfigErr := config.Sync()
if syncConfigErr != nil { }
parseConfigErr := config.Scan(&conf)
if parseConfigErr != nil { }
loggerConfigInitiator(&conf.Loggers)
return conf
}