mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 20:27:23 +00:00
Initial commit
This commit is contained in:
26
server/utils/storage.go
Normal file
26
server/utils/storage.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var path string
|
||||
|
||||
func GetStoragePath() string {
|
||||
if path != "" {
|
||||
return path
|
||||
}
|
||||
if runtime.GOOS == "linux" {
|
||||
path = "/var/lib/nysoure"
|
||||
} else {
|
||||
userDir, _ := os.UserHomeDir()
|
||||
path = userDir + "/.nysoure"
|
||||
}
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(path, os.ModePerm); err != nil {
|
||||
panic("failed to create storage directory")
|
||||
}
|
||||
}
|
||||
return path
|
||||
}
|
Reference in New Issue
Block a user