-
Notifications
You must be signed in to change notification settings - Fork 48
/
config.go
83 lines (70 loc) · 1.92 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
77
78
79
80
81
82
83
package config
import (
"github.com/spf13/viper"
"log"
"os"
)
var AppPath string
type System struct {
JoinHintAfterDelTime int `mapstructure:"join_hint_after_del_time"`
CaptchaTimeout int `mapstructure:"captcha_timeout"`
RuntimePath string `mapstructure:"runtime_path"`
}
var SystemC System
type Telegram struct {
BotToken string `mapstructure:"bot_token"`
ApiProxy string `mapstructure:"api_proxy"`
ManageUsers []int64 `mapstructure:"manage_users"`
}
var TelegramC Telegram
type Log struct {
MaxSize int `mapstructure:"max_size"`
MaxAge int `mapstructure:"max_age"`
MaxBackups int `mapstructure:"max_backups"`
}
var LogC Log
type Message struct {
JoinHint string `mapstructure:"join_hint"`
CaptchaImage string `mapstructure:"captcha_image"`
VerificationComplete string `mapstructure:"verification_complete"`
BlockHint string `mapstructure:"block_hint"`
}
var MessageC Message
type AdBlock struct {
NumberOfForbiddenWords int `mapstructure:"number_of_forbidden_words"`
BlockTime int64 `mapstructure:"block_time"`
}
var AdBlockC AdBlock
// InitConfig 配置加载
func InitConfig() {
path, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
AppPath = path
viper.SetConfigFile(path + "/config/config.toml")
err = viper.ReadInConfig()
if err != nil {
log.Fatal("load config file err:", err)
}
err = viper.UnmarshalKey("system", &SystemC)
if err != nil {
log.Fatal("load config system err:", err)
}
err = viper.UnmarshalKey("telegram", &TelegramC)
if err != nil {
log.Fatal("load config telegram err:", err)
}
err = viper.UnmarshalKey("log", &LogC)
if err != nil {
log.Fatal("load config log err:", err)
}
err = viper.UnmarshalKey("message", &MessageC)
if err != nil {
log.Fatal("load config message err:", err)
}
err = viper.UnmarshalKey("adblock", &AdBlockC)
if err != nil {
log.Fatal("load config adblock err:", err)
}
}