shiori/path-generator.go

48 lines
903 B
Go
Raw Normal View History

// +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()
databaseName = getDatabaseName()
// Make sure directory exist
2018-05-18 17:18:38 +08:00
os.MkdirAll(dataDir, os.ModePerm)
}
2018-05-18 17:18:38 +08:00
func getDataDirectory() string {
// Try to look at environment variables
2018-05-18 17:18:38 +08:00
dataDir, found := os.LookupEnv("ENV_SHIORI_DIR")
if found {
2018-05-18 17:18:38 +08:00
return dataDir
}
// 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-18 17:18:38 +08:00
// When all fail, use current working directory
return "."
}
func getDatabaseName() string {
// Try to look at environment variables
databaseName, found := os.LookupEnv("ENV_SHIORI_DB")
if found {
return databaseName
}
// When all fail, use current working directory
return "shiori.db"
}