2023-12-13 17:59:14 +08:00
|
|
|
package utils
|
2023-12-08 22:02:36 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetExecDir() string {
|
2023-12-27 17:22:18 +08:00
|
|
|
if os.Getenv("GoHTTPD_Home") != "" {
|
|
|
|
return os.Getenv("GoHTTPD_Home")
|
|
|
|
}
|
2023-12-08 22:02:36 +08:00
|
|
|
execPath, err := os.Executable()
|
2023-12-27 17:22:18 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
rpath, err := filepath.EvalSymlinks(execPath)
|
2023-12-08 22:02:36 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2023-12-27 17:22:18 +08:00
|
|
|
rpath, _ = filepath.Abs(rpath)
|
|
|
|
return filepath.Dir(rpath)
|
2023-12-08 22:02:36 +08:00
|
|
|
}
|
2023-12-13 09:22:05 +08:00
|
|
|
|
|
|
|
func NormalizePath(path string) string {
|
|
|
|
// return filepath.ToSlash(filepath.Clean(path))
|
|
|
|
p := filepath.ToSlash(path)
|
|
|
|
if filepath.IsAbs(p) {
|
|
|
|
return p
|
|
|
|
} else {
|
|
|
|
return filepath.Join(GetExecDir(), p)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|