Skip to content

Commit

Permalink
Merge pull request go-shiori#97 from sascha-andres/feature/database-name
Browse files Browse the repository at this point in the history
feature/database name: allow setting a different database name
  • Loading branch information
RadhiFadlillah authored Jun 8, 2018
2 parents e63a9d0 + 4a1c364 commit e981017
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 e981017

Please sign in to comment.