fix: decouple project root resolution from custom BH_CONFIG_PATH env

This commit is contained in:
duorameng
2026-05-18 17:26:30 +08:00
parent e8feeb0fcd
commit 28346bf6b4
2 changed files with 3 additions and 24 deletions
+2 -8
View File
@@ -34,13 +34,7 @@ func init() {
// ResolveAppRootDir 获取应用程序的绝对根目录路径。
func ResolveAppRootDir() string {
// 1. 检查 BH_CONFIG_PATH 环境变量
if configPath := os.Getenv("BH_CONFIG_PATH"); configPath != "" {
if absConfigPath, err := filepath.Abs(configPath); err == nil {
return filepath.Dir(filepath.Dir(absConfigPath))
}
}
// 2. 检查当前可执行文件路径
// 1. 检查当前可执行文件路径
if exe, err := os.Executable(); err == nil {
dir := filepath.Dir(exe)
for {
@@ -57,7 +51,7 @@ func ResolveAppRootDir() string {
dir = parent
}
}
// 3. 回退到当前工作目录
// 2. 回退到当前工作目录
if cwd, err := os.Getwd(); err == nil {
return cwd
}