Skip to content

Commit

Permalink
feat: allow to change database file name
Browse files Browse the repository at this point in the history
restore complete customization go-shiori#93
  • Loading branch information
Sascha Andres committed Jun 6, 2018
1 parent 4c449e0 commit 4a1c364
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions path-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
func init() {
// Get data directory
dataDir = getDataDirectory()
databaseName = getDatabaseName()

// Make sure directory exist
os.MkdirAll(dataDir, os.ModePerm)
Expand All @@ -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"
}

0 comments on commit 4a1c364

Please sign in to comment.