/
config.go
50 lines (44 loc) · 850 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
38
39
40
41
42
43
44
45
46
47
48
49
50
package config
import (
"os"
"path/filepath"
"github.com/BurntSushi/toml"
)
type config struct {
BotConf BotConfig
}
func GetWechatConfig() *config {
var err error
path_ := os.Getenv("WECHAT_CONFIG_PATH")
if path_ == "" {
dir, err := os.UserConfigDir()
if err != nil {
panic(err)
}
path_ = filepath.Join(dir, "wechat", ".config", "wechat.toml")
}
conf := config{}
_, err = toml.DecodeFile(path_, &conf)
if err != nil {
panic(err)
}
return &conf
}
type BotConfig struct {
CorpId string
Agent string
Secret string
UserAgent string
Protocol string
Host string
Port int
GetTokenUri string
SendMsgUri string
UserId string
Token string
EncodingAESKey string
}
func GetBot() *BotConfig {
c := GetWechatConfig()
return &c.BotConf
}