Move opening database to main file

This commit is contained in:
Radhi Fadlillah 2018-03-05 07:14:58 +07:00
parent 1ae90b7459
commit c208894bb6
2 changed files with 25 additions and 17 deletions

View file

@ -2,19 +2,19 @@ package cmd
import (
"fmt"
"github.com/spf13/cobra"
"os"
db "github.com/RadhiFadlillah/shiori/database"
_ "github.com/mattn/go-sqlite3"
"github.com/RadhiFadlillah/shiori/database"
"github.com/spf13/cobra"
)
var (
// DB is database that used by this cli
DB db.Database
DB database.Database
rootCmd = &cobra.Command{
Use: "shiori",
Short: "Simple command-line bookmark manager built with Go.",
Short: "Simple command-line bookmark manager built with Go",
}
)
@ -26,14 +26,3 @@ func Execute() {
os.Exit(1)
}
}
func init () {
databasePath := "shiori.db"
if value, found := os.LookupEnv("ENV_SHIORI_DB"); found {
databasePath = value
}
sqliteDB, err := db.OpenSQLiteDatabase(databasePath)
checkError(err)
DB = sqliteDB
}

21
main.go
View file

@ -2,9 +2,28 @@
package main
import (
"os"
"github.com/RadhiFadlillah/shiori/cmd"
db "github.com/RadhiFadlillah/shiori/database"
_ "github.com/mattn/go-sqlite3"
)
func main() {
databasePath := "shiori.db"
if value, found := os.LookupEnv("ENV_SHIORI_DB"); found {
databasePath = value
}
sqliteDB, err := db.OpenSQLiteDatabase(databasePath)
checkError(err)
cmd.DB = sqliteDB
cmd.Execute()
}
}
func checkError(err error) {
if err != nil {
panic(err)
}
}