fix: try to fix cmd lost init envs

This commit is contained in:
duorameng
2026-05-13 18:00:57 +08:00
parent 9c3af05753
commit c211a19dd8
2 changed files with 21 additions and 9 deletions
+3
View File
@@ -71,6 +71,9 @@ func Run(args []string) {
user := userService.GetUserByUsername(username)
if user == nil {
fmt.Printf("找不到用户 [%s]\n", username)
fmt.Println(">> 提示: 程序当前可能连接到了默认的空 SQLite 数据库。")
fmt.Println(">> 若您的生产环境使用的是 MySQL 或指定路径配置,请在执行命令时携带配置文件路径环境变量,例如:")
fmt.Println(">> BH_CONFIG_PATH=/app/data/config.ini baihu resetpwd " + username)
return
}
+18 -9
View File
@@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"runtime"
"sync"
"time"
"github.com/engigu/baihu-panel/internal/constant"
@@ -30,16 +31,24 @@ func New() *App {
return app
}
var (
globalApp *App
initOnce sync.Once
)
func InitBasic() *App {
app := &App{}
utils.InitRuntime()
utils.InitSecretKey()
// 自动加载配置 (内部会自动处理 BH_CONFIG_PATH 环境变量与默认路径的优先级)
app.initConfigWithPath("")
app.initDatabase()
logger.Infof("[System] 低于1.0.11版本升级最新版本错误指引: https://github.com/engigu/baihu-panel/issues/64")
return app
initOnce.Do(func() {
app := &App{}
utils.InitRuntime()
utils.InitSecretKey()
// 自动加载配置 (内部会自动处理 BH_CONFIG_PATH 环境变量与默认路径的优先级)
app.initConfigWithPath("")
app.initDatabase()
logger.Infof("[System] 低于1.0.11版本升级最新版本错误指引: https://github.com/engigu/baihu-panel/issues/64")
globalApp = app
})
return globalApp
}
// InitBasicForCmd 专为命令行工具定制的基础环境初始化入口