mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-04-28 11:30:15 +00:00
- Fix deadlock and race conditions in internal/alerts - Add comprehensive error path tests for internal/config - Fix 401 handling in internal/api - Fix Docker Swarm task filtering test logic
42 lines
921 B
Go
42 lines
921 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
osExecutable = os.Executable
|
|
osGetwd = os.Getwd
|
|
)
|
|
|
|
// detectAppRoot attempts to find the application root directory
|
|
func detectAppRoot() string {
|
|
// 1. Check environment variable
|
|
if root := os.Getenv("PULSE_APP_ROOT"); root != "" {
|
|
return root
|
|
}
|
|
|
|
// 2. Get executable path
|
|
exe, err := osExecutable()
|
|
if err == nil {
|
|
// If running via "go run", executable is in /tmp, which isn't helpful for finding source files
|
|
// But in production, it's correct.
|
|
// Check if we are in a temp dir (go run)
|
|
if strings.Contains(exe, os.TempDir()) || strings.Contains(exe, "/var/folders/") {
|
|
// Fallback to current working directory
|
|
if cwd, err := osGetwd(); err == nil {
|
|
return cwd
|
|
}
|
|
}
|
|
return filepath.Dir(exe)
|
|
}
|
|
|
|
// 3. Fallback to current working directory
|
|
if cwd, err := osGetwd(); err == nil {
|
|
return cwd
|
|
}
|
|
|
|
return "."
|
|
}
|