mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-06 19:38:36 +08:00
fix: unable to build go backend (#16542)
This commit is contained in:
@@ -376,6 +376,12 @@ func TestLoadFieldMapping_ParsesAliases(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadFieldMapping_EmptyNameDefaultsToInfinityMappingJSON(t *testing.T) {
|
||||
// Ensure the test runs in an isolated project base so any repo file
|
||||
// named "infinity_mapping.json" doesn't get picked up.
|
||||
dir := t.TempDir()
|
||||
os.Setenv("RAG_PROJECT_BASE", dir)
|
||||
defer os.Unsetenv("RAG_PROJECT_BASE")
|
||||
|
||||
// Empty name → defaults to "infinity_mapping.json" (line 145).
|
||||
// We just verify the function doesn't panic and the file-not-found
|
||||
// path is taken silently.
|
||||
|
||||
@@ -19,11 +19,15 @@ package utility
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// GetProjectRoot returns the project root directory
|
||||
func GetProjectRoot() string {
|
||||
// Try environment variable first
|
||||
if confDir := os.Getenv("RAGFLOW_CONF_DIR"); confDir != "" {
|
||||
return confDir
|
||||
}
|
||||
if d := os.Getenv("RAG_PROJECT_BASE"); d != "" {
|
||||
return d
|
||||
}
|
||||
@@ -31,8 +35,23 @@ func GetProjectRoot() string {
|
||||
return d
|
||||
}
|
||||
|
||||
// The binary is always at <project_root>/bin/, so going up 2 levels from
|
||||
// the executable path gives the project root.
|
||||
// Find project root by looking for go.mod from this source file.
|
||||
_, curFile, _, ok := runtime.Caller(0)
|
||||
if ok {
|
||||
dir := filepath.Dir(curFile)
|
||||
for {
|
||||
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
|
||||
return dir
|
||||
}
|
||||
parent := filepath.Dir(dir)
|
||||
if parent == dir {
|
||||
break
|
||||
}
|
||||
dir = parent
|
||||
}
|
||||
}
|
||||
|
||||
// Deployment binaries are normally at <project_root>/bin/.
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
return "."
|
||||
|
||||
Reference in New Issue
Block a user