- 替换 Beego 框架为 GoFrame v2 - 重构项目结构: controller/service/dao/middleware 分层 - 替换自定义 crons 包为 gcron - 模板从 views/ 迁移到 resource/template/ - 配置从 conf/app.conf 迁移到 config.yml - 数据库从 MySQL 切换为 SQLite (modernc.org/sqlite) - 移除 agent/ 远程执行器(待后续迁移) - 移除 crons/ 自定义定时器包 - 静态资源整理到 resource/static/
33 lines
672 B
Go
33 lines
672 B
Go
package boot
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
_ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
|
|
)
|
|
|
|
func init() {
|
|
ctx := context.Background()
|
|
|
|
dbPath := g.Cfg().MustGet(ctx, "database.default.name", "./data/ppgo_job.db").String()
|
|
|
|
// 相对路径 → 转为工作目录下的绝对路径
|
|
if !filepath.IsAbs(dbPath) {
|
|
wd, err := os.Getwd()
|
|
if err == nil {
|
|
dbPath = filepath.Join(wd, dbPath)
|
|
}
|
|
}
|
|
|
|
dir := filepath.Dir(dbPath)
|
|
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
|
|
g.Log().Fatalf(ctx, "创建数据目录失败: %v", err)
|
|
}
|
|
|
|
g.Log().Info(ctx, fmt.Sprintf("数据库路径: %s", dbPath))
|
|
}
|