/
config.go
37 lines (34 loc) · 886 Bytes
/
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
package utils
import (
"fmt"
"github.com/getsentry/sentry-go"
"github.com/spf13/viper"
"time"
)
type Config struct {
DBConnection string
Categories []string
TelegramApiKey string
TelegramChannel string
Sentry string
ProxyURI string
}
func ReadConfig() Config {
viper.SetConfigName("config")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
sentry.CaptureException(err)
sentry.Flush(time.Second * 5)
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
config := Config{
DBConnection: viper.GetString("database.connection"),
Categories: viper.GetStringSlice("fc_categories"),
TelegramApiKey: viper.GetString("telegram.api_key"),
TelegramChannel: viper.GetString("telegram.channel"),
Sentry: viper.GetString("sentry"),
ProxyURI: viper.GetString("proxy"),
}
return config
}