Added flag for setting DB file path

This commit is contained in:
Anis Ahmad
2021-10-16 19:17:57 +06:00
parent eaba2373d3
commit 923f11be3e
5 changed files with 37 additions and 7 deletions

View File

@@ -15,10 +15,22 @@ import (
)
// ConnectStorm Create database connection
func ConnectStorm() *storm.DB {
dbPath := GetEnvStr("DB_FILE", "")
var err error
func ConnectStorm(dbFilePath string) *storm.DB {
var dbPath string
if dbFilePath != "" {
info, err := os.Stat(dbFilePath)
if err == nil && info.IsDir() {
fmt.Println("Mentioned DB path is a directory. Please specify a file or ignore to create automatically in home directory.")
os.Exit(1)
}
dbPath = dbFilePath
} else {
dbPath = GetEnvStr("DB_FILE", "")
}
var err error
if dbPath == "" {
// Try in home dir
dbPath, err = homedir.Expand("~/.geek-life/default.db")