mirror of
https://github.com/go-shiori/shiori.git
synced 2025-09-14 08:56:32 +08:00
feat: allow to change database file name
restore complete customization #93
This commit is contained in:
parent
4c449e09b0
commit
4a1c36463b
2 changed files with 14 additions and 1 deletions
3
main.go
3
main.go
|
@ -12,10 +12,11 @@ import (
|
|||
)
|
||||
|
||||
var dataDir = "."
|
||||
var databaseName = "shiori.db"
|
||||
|
||||
func main() {
|
||||
// Open database
|
||||
dbPath := fp.Join(dataDir, "shiori.db")
|
||||
dbPath := fp.Join(dataDir, databaseName)
|
||||
sqliteDB, err := dt.OpenSQLiteDatabase(dbPath)
|
||||
checkError(err)
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
func init() {
|
||||
// Get data directory
|
||||
dataDir = getDataDirectory()
|
||||
databaseName = getDatabaseName()
|
||||
|
||||
// Make sure directory exist
|
||||
os.MkdirAll(dataDir, os.ModePerm)
|
||||
|
@ -33,3 +34,14 @@ func getDataDirectory() string {
|
|||
// 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"
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue