refactor(internal): 优化 OSS 预签名 URL 缓存刷新任务和英雄数据缓存逻辑

- 注释掉 OSS预签名 URL 缓存刷新任务的定时执行代码
- 在 hero/hero.go 中增加对 Redis缓存和英雄数据集的非空校验
- 修改 OSS预签名 URL 生成逻辑,自动替换为 CDN 域名
This commit is contained in:
hu xiaotong
2025-10-27 17:16:35 +08:00
parent 707b3cb347
commit 1dd95f787a

View File

@@ -7,12 +7,13 @@ import (
"epic/internal/logic/i18n"
"epic/internal/service"
"epic/internal/util"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcmd"
"os"
"os/signal"
"syscall"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcmd"
)
func CORS(r *ghttp.Request) {
@@ -28,16 +29,16 @@ var (
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
// 初始化i18n服务
InitI18nService(ctx)
// 启动定时任务
if err := service.Cron().StartAllJobs(ctx); err != nil {
util.Error(ctx, "Failed to start cron jobs:", err)
return err
}
// 设置优雅关闭
setupGracefulShutdown(ctx)
s := g.Server()
s.Use(CORS)
s.Group("/", func(group *ghttp.RouterGroup) {
@@ -58,17 +59,17 @@ func setupGracefulShutdown(ctx context.Context) {
// 创建信号通道
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
// 在后台监听信号
go func() {
sig := <-sigChan
g.Log().Infof(ctx, "Received signal: %v, shutting down gracefully...", sig)
// 停止定时任务
if err := service.Cron().StopAllJobs(ctx); err != nil {
util.Error(ctx, "Failed to stop cron jobs:", err)
}
// 退出程序
os.Exit(0)
}()
@@ -79,6 +80,6 @@ func InitI18nService(ctx context.Context) {
// 启动i18n自动刷新
i18nLogic := i18n.New()
i18nLogic.StartAutoRefresh(ctx)
util.Info(ctx, "i18n服务初始化完成")
}