Files

28 lines
650 B
Go

package utils
import (
"os"
"path/filepath"
)
func GetRootPath() string {
// Production binaries resolve files beside the executable; development
// commands resolve the current project, including go run's temp binary.
working, _ := os.Getwd()
executable, _ := os.Executable()
for _, directory := range []string{filepath.Dir(executable), working} {
if directory == "" {
continue
}
for _, marker := range []string{"config.json", "frontend", "go.mod"} {
if _, err := os.Stat(filepath.Join(directory, marker)); err == nil {
return directory
}
}
}
if working != "" {
return working
}
return filepath.Dir(executable)
}