2022-07-27 10:21:49 +00:00
|
|
|
|
package conf
|
2021-11-12 07:46:33 +00:00
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
_ "embed"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2022-04-20 13:31:46 +00:00
|
|
|
|
"gopkg.in/yaml.v3"
|
2021-11-12 07:46:33 +00:00
|
|
|
|
)
|
|
|
|
|
|
2022-04-20 13:31:46 +00:00
|
|
|
|
// Config
|
|
|
|
|
// @Description:
|
|
|
|
|
//
|
2021-11-12 07:46:33 +00:00
|
|
|
|
type Config struct {
|
|
|
|
|
Model int `json:"model" yaml:"model"`
|
|
|
|
|
LogLevel string `json:"log_level" yaml:"log_level"`
|
|
|
|
|
ShowBrowser bool `json:"show_browser" yaml:"show_browser"`
|
2022-02-14 13:58:16 +00:00
|
|
|
|
Scheme string `json:"scheme" yaml:"scheme"`
|
2021-11-17 09:39:48 +00:00
|
|
|
|
Push struct {
|
|
|
|
|
Ding struct {
|
|
|
|
|
Enable bool `json:"enable" yaml:"enable"`
|
|
|
|
|
AccessToken string `json:"access_token" yaml:"access_token"`
|
|
|
|
|
Secret string `json:"secret" yaml:"secret"`
|
|
|
|
|
} `json:"ding" yaml:"ding"`
|
2021-11-22 12:07:55 +00:00
|
|
|
|
PushPlus struct {
|
|
|
|
|
Enable bool `json:"enable" yaml:"enable"`
|
|
|
|
|
Token string `json:"token" yaml:"token"`
|
|
|
|
|
} `json:"push_plus" yaml:"push_plus"`
|
2021-11-17 09:39:48 +00:00
|
|
|
|
} `json:"push" yaml:"push"`
|
2021-11-27 08:24:24 +00:00
|
|
|
|
TG struct {
|
|
|
|
|
Enable bool `json:"enable" yaml:"enable"`
|
|
|
|
|
Token string `json:"token" yaml:"token"`
|
|
|
|
|
ChatID int64 `json:"chat_id" yaml:"chat_id"`
|
|
|
|
|
Proxy string `json:"proxy" yaml:"proxy"`
|
|
|
|
|
} `json:"tg" yaml:"tg"`
|
2022-04-20 13:31:46 +00:00
|
|
|
|
QQ struct {
|
|
|
|
|
}
|
2022-02-16 07:10:38 +00:00
|
|
|
|
Web struct {
|
2022-04-20 13:31:46 +00:00
|
|
|
|
Enable bool `json:"enable" yaml:"enable"`
|
2022-04-11 03:19:26 +00:00
|
|
|
|
Account string `json:"account" yaml:"account"`
|
|
|
|
|
Password string `json:"password" yaml:"password"`
|
|
|
|
|
Host string `json:"host" yaml:"host"`
|
|
|
|
|
Port int `json:"port" yaml:"port"`
|
2022-02-16 07:10:38 +00:00
|
|
|
|
} `json:"web"`
|
2022-04-14 13:18:36 +00:00
|
|
|
|
Cron string `json:"cron" yaml:"cron"`
|
|
|
|
|
EdgePath string `json:"edge_path" yaml:"edge_path"`
|
|
|
|
|
QrCOde bool `json:"qr_code" yaml:"qr_code"`
|
|
|
|
|
StartWait int `json:"start_wait" yaml:"start_wait"`
|
2022-05-03 11:35:14 +00:00
|
|
|
|
// cookie强制过期时间,单位为h
|
|
|
|
|
ForceExpiration int `json:"force_expiration" yaml:"force_expiration"`
|
|
|
|
|
Retry struct {
|
|
|
|
|
// 重试次数
|
|
|
|
|
Times int `json:"times" yaml:"times"`
|
|
|
|
|
// 重试时间
|
|
|
|
|
Intervals int `json:"intervals" yaml:"intervals"`
|
|
|
|
|
} `json:"retry" yaml:"retry"`
|
2022-07-30 10:55:00 +00:00
|
|
|
|
|
|
|
|
|
Wechat struct {
|
2022-07-31 12:33:39 +00:00
|
|
|
|
Enable bool `json:"enable" yaml:"enable"`
|
|
|
|
|
Token string `json:"token" yaml:"token"`
|
|
|
|
|
Secret string `json:"secret" yaml:"secret"`
|
|
|
|
|
AppID string `json:"app_id" yaml:"app_id"`
|
|
|
|
|
LoginTempID string `json:"login_temp_id" yaml:"login_temp_id"`
|
|
|
|
|
NormalTempID string `json:"normal_temp_id" yaml:"normal_temp_id"`
|
|
|
|
|
PushLoginWarn bool `json:"push_login_warn" yaml:"push_login_warn"`
|
2022-07-30 10:55:00 +00:00
|
|
|
|
} `json:"wechat" yaml:"wechat"`
|
2022-05-27 12:20:15 +00:00
|
|
|
|
// 专项答题可接受的最小值
|
|
|
|
|
SpecialMinScore int `json:"special_min_score" yaml:"special_min_score"`
|
2022-07-24 07:56:12 +00:00
|
|
|
|
|
|
|
|
|
JiGuangPush struct {
|
|
|
|
|
Enable bool `json:"enable" yaml:"enable"`
|
|
|
|
|
Secret string `json:"secret" yaml:"secret"`
|
|
|
|
|
AppKey string `json:"app_key" yaml:"app_key"`
|
|
|
|
|
} `json:"ji_guang_push" yaml:"ji_guang_push"`
|
2021-11-12 07:46:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
config = Config{
|
|
|
|
|
Model: 1,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//go:embed config_default.yml
|
|
|
|
|
var defaultConfig []byte
|
|
|
|
|
|
2022-02-16 07:10:38 +00:00
|
|
|
|
// GetConfig
|
|
|
|
|
/**
|
|
|
|
|
* @Description:
|
|
|
|
|
* @return Config
|
|
|
|
|
*/
|
2021-11-12 07:46:33 +00:00
|
|
|
|
func GetConfig() Config {
|
|
|
|
|
file, err := os.ReadFile("./config/config.yml")
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Warningln("检测到配置文件可能不存在")
|
|
|
|
|
err := os.WriteFile("./config/config.yml", defaultConfig, 0666)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorln("写入到配置文件出现错误")
|
2022-04-25 10:39:54 +00:00
|
|
|
|
log.Errorln(err.Error())
|
2021-11-12 07:46:33 +00:00
|
|
|
|
return Config{}
|
|
|
|
|
}
|
|
|
|
|
log.Infoln("成功写入到配置文件,请重启应用")
|
|
|
|
|
os.Exit(3)
|
|
|
|
|
}
|
|
|
|
|
err = yaml.Unmarshal(file, &config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorln(err.Error())
|
|
|
|
|
return Config{}
|
|
|
|
|
}
|
2022-02-16 07:12:16 +00:00
|
|
|
|
if config.Scheme == "" {
|
|
|
|
|
config.Scheme = "https://johlanse.github.io/study_xxqg/scheme.html?"
|
|
|
|
|
}
|
2022-05-27 12:20:15 +00:00
|
|
|
|
if config.SpecialMinScore == 0 {
|
|
|
|
|
config.SpecialMinScore = 10
|
|
|
|
|
}
|
2021-11-12 07:46:33 +00:00
|
|
|
|
return config
|
|
|
|
|
}
|