33 lines
845 B
Go
33 lines
845 B
Go
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")
|
|
}
|
|
}
|