2018-05-01 11:23:38 +08:00
|
|
|
// +build !dev
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
apppaths "github.com/muesli/go-app-paths"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2018-05-18 17:18:38 +08:00
|
|
|
// Get data directory
|
|
|
|
dataDir = getDataDirectory()
|
2018-05-01 11:23:38 +08:00
|
|
|
|
|
|
|
// Make sure directory exist
|
2018-05-18 17:18:38 +08:00
|
|
|
os.MkdirAll(dataDir, os.ModePerm)
|
2018-05-01 11:23:38 +08:00
|
|
|
}
|
|
|
|
|
2018-05-18 17:18:38 +08:00
|
|
|
func getDataDirectory() string {
|
2018-05-01 11:23:38 +08:00
|
|
|
// Try to look at environment variables
|
2018-05-18 17:18:38 +08:00
|
|
|
dataDir, found := os.LookupEnv("ENV_SHIORI_DIR")
|
2018-05-01 11:23:38 +08:00
|
|
|
if found {
|
2018-05-18 17:18:38 +08:00
|
|
|
return dataDir
|
2018-05-01 11:23:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try to use platform specific app path
|
|
|
|
userScope := apppaths.NewScope(apppaths.User, "shiori", "shiori")
|
|
|
|
dataDir, err := userScope.DataDir()
|
|
|
|
if err == nil {
|
2018-05-18 17:18:38 +08:00
|
|
|
return dataDir
|
2018-05-01 11:23:38 +08:00
|
|
|
}
|
|
|
|
|
2018-05-18 17:18:38 +08:00
|
|
|
// When all fail, use current working directory
|
|
|
|
return "."
|
2018-05-01 11:23:38 +08:00
|
|
|
}
|