-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
89 lines (78 loc) · 2.04 KB
/
main.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
84
85
86
87
88
89
package main
import (
"encoding/json"
"errors"
"genshinBirthdayHelper/helper"
"github.com/rroy233/logger"
"log"
"os"
"time"
)
type ConfigStruct struct {
Accounts []helper.Account `json:"accounts"`
Logger struct {
Enabled bool `json:"enabled"`
Report bool `json:"report"`
ReportUrl string `json:"reportUrl"`
QueryKey string `json:"queryKey"`
} `json:"logger,omitempty"`
}
var config *ConfigStruct
func main() {
//读取配置
err := loadConfig()
if err != nil {
log.Fatalln("读取配置发生错误:", err)
}
//日志服务
if config.Logger.Enabled == true {
logger.New(&logger.Config{
StdOutput: true,
StoreLocalFile: config.Logger.Enabled,
StoreRemote: config.Logger.Report,
NotUseJson: true,
RemoteConfig: logger.RemoteConfigStruct{
RequestUrl: config.Logger.ReportUrl,
QueryKey: config.Logger.QueryKey,
},
})
} else {
logger.New(&logger.Config{
StdOutput: true,
})
}
for i, account := range config.Accounts {
//初始化
h, err := helper.New(account)
if err != nil {
logger.FATAL.Fatalf("【账号-%d】初始化失败:%s", i, err.Error())
}
err = h.Do()
if err != nil {
logger.FATAL.Fatalf("【账号-%d】执行失败:%s", i, err.Error())
}
}
defer func() {
time.Sleep(200 * time.Millisecond)
}()
}
func loadConfig() error {
//检查config.json是否存在
_, err := os.Open("./config.json")
if err != nil {
if os.IsNotExist(err) == true {
os.WriteFile("./config.json", []byte("{\n\t\"accounts\": [{\n\t\t\"server\": \"cn_gf01\",\n\t\t\"uid\": \"xxx\",\n\t\t\"mys-cookie\": \"\"\n\t}],\n\t\"logger\": {\n\t\t\"enabled\": true,\n\t\t\"report\": false,\n\t\t\"reportUrl\": \"http://localhost/api/logUpload\",\n\t\t\"queryKey\": \"?key=xxxx\"\n\t}\n}"), 0755)
return errors.New("配置文件不存在,已自动创建,请手动填入cookie。")
}
}
data, err := os.ReadFile("./config.json")
if err != nil {
return err
}
config = new(ConfigStruct)
err = json.Unmarshal(data, config)
if err != nil {
return err
}
return nil
}