feat(platform): 多平台检测/路径/信号/系统信息(含跨平台构建验证)
This commit is contained in:
1 parent
efed5f05b1
commit
1d4bed415f
6 files changed
+276
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package platform
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// DefaultDataDir returns the OS-appropriate default data directory when the
|
||||
// user has not configured one. It never returns an empty path; on failure it
|
||||
// falls back to a relative "./data" directory.
|
||||
func DefaultDataDir() string {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return filepath.Join(".", "data")
|
||||
}
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
if appdata := os.Getenv("APPDATA"); appdata != "" {
|
||||
return filepath.Join(appdata, "Cyrene")
|
||||
}
|
||||
return filepath.Join(home, "AppData", "Roaming", "Cyrene")
|
||||
case "darwin":
|
||||
return filepath.Join(home, "Library", "Application Support", "Cyrene")
|
||||
default:
|
||||
if xdg := os.Getenv("XDG_DATA_HOME"); xdg != "" {
|
||||
return filepath.Join(xdg, "cyrene")
|
||||
}
|
||||
return filepath.Join(home, ".local", "share", "cyrene")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user