MCPcopy Create free account
hub / github.com/djun/wechatbot / LoadConfig

Function LoadConfig

config/config.go:22–50  ·  view source on GitHub ↗

LoadConfig 加载配置

()

Source from the content-addressed store, hash-verified

20
21// LoadConfig 加载配置
22func LoadConfig() *Configuration {
23 once.Do(func() {
24 // 从文件中读取
25 config = &Configuration{}
26 f, err := os.Open("config.json")
27 if err != nil {
28 log.Fatalf("open config err: %v", err)
29 return
30 }
31 defer f.Close()
32 encoder := json.NewDecoder(f)
33 err = encoder.Decode(config)
34 if err != nil {
35 log.Fatalf("decode config err: %v", err)
36 return
37 }
38
39 // 如果环境变量有配置,读取环境变量
40 ApiKey := os.Getenv("ApiKey")
41 AutoPass := os.Getenv("AutoPass")
42 if ApiKey != "" {
43 config.ApiKey = ApiKey
44 }
45 if AutoPass == "true" {
46 config.AutoPass = true
47 }
48 })
49 return config
50}

Callers 2

HandlerFunction · 0.92
CompletionsFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected