diff --git a/Dockerfile b/Dockerfile index ce3bb29..68e4e6a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ COPY ./output/study_xxqg /opt/study_xxqg RUN mkdir /opt/config/ -COPY ./lib/config_default.yml /opt/config/config.yml +COPY conf/config_default.yml /opt/config/config.yml RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl \ diff --git a/lib/config.go b/conf/config.go similarity index 99% rename from lib/config.go rename to conf/config.go index 91d2b29..ab68556 100644 --- a/lib/config.go +++ b/conf/config.go @@ -1,4 +1,4 @@ -package lib +package conf import ( _ "embed" diff --git a/lib/config_default.yml b/conf/config_default.yml similarity index 100% rename from lib/config_default.yml rename to conf/config_default.yml diff --git a/lib/core.go b/lib/core.go index a21f541..1ae711a 100644 --- a/lib/core.go +++ b/lib/core.go @@ -26,6 +26,7 @@ import ( goqrcode "github.com/skip2/go-qrcode" "golang.org/x/image/bmp" + "github.com/huoxue1/study_xxqg/conf" "github.com/huoxue1/study_xxqg/model" ) @@ -158,14 +159,14 @@ func (c *Core) GenerateCode() (string, string, error) { } else { log.Infoln("二维码已生成到目录下的qrcode.png") } - if GetConfig().QrCOde { + if conf.GetConfig().QrCOde { data, _ := os.ReadFile("qrcode.png") c.Push("image", base64.StdEncoding.EncodeToString(data)) } qrCodeString := qrcodeTerminal.New2(qrcodeTerminal.ConsoleColors.BrightBlack, qrcodeTerminal.ConsoleColors.BrightWhite, qrcodeTerminal.QRCodeRecoveryLevels.Low).Get(codeURL) qrCodeString.Print() - c.Push("flush", "登录链接:\r\n"+config.Scheme+url.QueryEscape(codeURL)) + c.Push("flush", "登录链接:\r\n"+conf.GetConfig().Scheme+url.QueryEscape(codeURL)) return codeURL, g.Result, err } @@ -256,7 +257,7 @@ func (c *Core) L(retryTimes int) (*model.User, error) { return nil, errors.New("time out") } else { // 等待几分钟后重新执行 - time.Sleep(time.Duration(GetConfig().Retry.Intervals) * time.Minute) + time.Sleep(time.Duration(conf.GetConfig().Retry.Intervals) * time.Minute) c.Push("text", fmt.Sprintf("登录超时,将进行第%d重新次登录", retryTimes)) return c.L(retryTimes - 1) } @@ -279,7 +280,7 @@ func (c *Core) initWindows() { return } c.pw = pwt - path := GetConfig().EdgePath + path := conf.GetConfig().EdgePath if path == "" { path = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe" } diff --git a/lib/tg.go b/lib/tg.go index ca44617..9e1d6c1 100644 --- a/lib/tg.go +++ b/lib/tg.go @@ -14,6 +14,7 @@ import ( "github.com/google/uuid" log "github.com/sirupsen/logrus" + "github.com/huoxue1/study_xxqg/conf" "github.com/huoxue1/study_xxqg/model" ) @@ -90,7 +91,7 @@ func (t *Telegram) Init() { update := <-channel if update.Message == nil { update.Message = &tgbotapi.Message{Text: update.CallbackQuery.Data} - t.bot.Send(tgbotapi.NewDeleteMessage(config.TG.ChatID, update.CallbackQuery.Message.MessageID)) + t.bot.Send(tgbotapi.NewDeleteMessage(conf.GetConfig().TG.ChatID, update.CallbackQuery.Message.MessageID)) log.Infoln(update.CallbackQuery.Data) } log.Infoln("收到tg消息 ", update) @@ -149,7 +150,7 @@ func (t *Telegram) SendMsg(message string) int { } func login(bot *Telegram, args []string) { - config := GetConfig() + config := conf.GetConfig() go func() { defer func() { err := recover() @@ -202,7 +203,7 @@ func getAllUser(bot *Telegram, args []string) { } func studyAll(bot *Telegram, args []string) { - config := GetConfig() + config := conf.GetConfig() users, err := model.Query() if err != nil { bot.SendMsg(err.Error()) @@ -272,7 +273,7 @@ func studyAll(bot *Telegram, args []string) { } func study(bot *Telegram, args []string) { - config := GetConfig() + config := conf.GetConfig() users, err := model.Query() if err != nil { bot.SendMsg(err.Error()) diff --git a/main.go b/main.go index 1cfe370..00b6b36 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( log "github.com/sirupsen/logrus" easy "github.com/t-tomalak/logrus-easy-formatter" + "github.com/huoxue1/study_xxqg/conf" //"github.com/huoxue1/study_xxqg/gui" "github.com/huoxue1/study_xxqg/lib" "github.com/huoxue1/study_xxqg/model" @@ -34,7 +35,7 @@ func init() { flag.BoolVar(&i, "init", false, "init the app") flag.Parse() - config = lib.GetConfig() + config = conf.GetConfig() logFormatter := &easy.Formatter{ TimestampFormat: "2006-01-02 15:04:05", LogFormat: "[%time%] [%lvl%]: %msg% \n", @@ -64,7 +65,7 @@ func init() { } var ( - config lib.Config + config conf.Config ) func init() { diff --git a/push/jpush.go b/push/jpush.go index e2d92ab..3feb914 100644 --- a/push/jpush.go +++ b/push/jpush.go @@ -6,11 +6,11 @@ import ( "github.com/imroc/req/v3" - "github.com/huoxue1/study_xxqg/lib" + "github.com/huoxue1/study_xxqg/conf" ) func PushMessage(title, content, message, pushID string) error { - if !lib.GetConfig().JiGuangPush.Enable { + if !conf.GetConfig().JiGuangPush.Enable { return nil } @@ -26,7 +26,7 @@ func PushMessage(title, content, message, pushID string) error { "message": map[string]string{ "msg_content": message, }, - }).SetHeader("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(lib.GetConfig().JiGuangPush.AppKey+":"+lib.GetConfig().JiGuangPush.Secret))).Post("https://api.jpush.cn/v3/push") + }).SetHeader("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(conf.GetConfig().JiGuangPush.AppKey+":"+conf.GetConfig().JiGuangPush.Secret))).Post("https://api.jpush.cn/v3/push") if err != nil { return err } diff --git a/push/push.go b/push/push.go index e627427..122530b 100644 --- a/push/push.go +++ b/push/push.go @@ -3,10 +3,10 @@ package push import ( log "github.com/sirupsen/logrus" - "github.com/huoxue1/study_xxqg/lib" + "github.com/huoxue1/study_xxqg/conf" ) -func GetPush(config lib.Config) func(kind string, message string) { +func GetPush(config conf.Config) func(kind string, message string) { if config.Push.Ding.Enable { ding := &Ding{ Secret: config.Push.Ding.Secret, diff --git a/web/controller.go b/web/controller.go index 4608fdf..3bda6e5 100644 --- a/web/controller.go +++ b/web/controller.go @@ -12,6 +12,7 @@ import ( "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" + "github.com/huoxue1/study_xxqg/conf" "github.com/huoxue1/study_xxqg/lib" "github.com/huoxue1/study_xxqg/model" "github.com/huoxue1/study_xxqg/push" @@ -25,7 +26,7 @@ var ( func CheckToken() gin.HandlerFunc { return func(ctx *gin.Context) { token := ctx.Param("token") - config := lib.GetConfig() + config := conf.GetConfig() md5 := utils.StrMd5(config.Web.Account + config.Web.Password) if md5 == token { ctx.JSON(200, Resp{ @@ -55,7 +56,7 @@ func Login() gin.HandlerFunc { } u := new(user) _ = ctx.BindJSON(u) - config := lib.GetConfig() + config := conf.GetConfig() if u.Account == config.Web.Account && u.Password == config.Web.Password { ctx.JSON(200, Resp{ Code: 200, @@ -220,7 +221,7 @@ func study() gin.HandlerFunc { } core.Init() state.Store(uid, core) - config := lib.GetConfig() + config := conf.GetConfig() go func() { core.LearnArticle(user) core.LearnVideo(user) diff --git a/web/router.go b/web/router.go index d09ee58..0e77543 100644 --- a/web/router.go +++ b/web/router.go @@ -6,7 +6,7 @@ import ( "github.com/gin-gonic/gin" - "github.com/huoxue1/study_xxqg/lib" + "github.com/huoxue1/study_xxqg/conf" "github.com/huoxue1/study_xxqg/utils" ) @@ -54,7 +54,7 @@ func RouterInit() *gin.Engine { } func check() gin.HandlerFunc { - config := lib.GetConfig() + config := conf.GetConfig() return func(ctx *gin.Context) { token := ctx.GetHeader("xxqg_token") if token == "" || (utils.StrMd5(config.Web.Account+config.Web.Password) != token) {