mirror of
https://github.com/go-shiori/shiori.git
synced 2025-09-12 07:55:35 +08:00
Move opening database to main file
This commit is contained in:
parent
1ae90b7459
commit
c208894bb6
2 changed files with 25 additions and 17 deletions
21
cmd/root.go
21
cmd/root.go
|
@ -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
21
main.go
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue