mirror of https://github.com/fmartingr/shiori.git
Change default database to home dir
This commit is contained in:
parent
468430063c
commit
6bab302785
|
@ -64,7 +64,10 @@ Use "shiori [command] --help" for more information about a command.
|
|||
|
||||
## Advanced
|
||||
|
||||
By default, `shiori` will create database in the location where you run it. For example, if you run `shiori`. To set the database to a specific location, you can set the environment variable `ENV_SHIORI_DB` to your desired path.
|
||||
By default, `shiori` will create database in `$HOME/.shiori.db`. If you want to set the database to another location, you can set the environment variable `ENV_SHIORI_DB` to your desired path :
|
||||
|
||||
- If `ENV_SHIORI_DB` points to a directory, it will create `.shiori.db` file inside that directory, so the final path for database is `$ENV_SHIORI_DB/.shiori.db`.
|
||||
- Else, it will create a new database file in the specified path.
|
||||
|
||||
## Usage with Docker
|
||||
|
||||
|
|
16
main.go
16
main.go
|
@ -3,6 +3,7 @@ package main
|
|||
|
||||
import (
|
||||
"os"
|
||||
"os/user"
|
||||
fp "path/filepath"
|
||||
|
||||
"github.com/RadhiFadlillah/shiori/cmd"
|
||||
|
@ -11,11 +12,11 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
databasePath := "shiori.db"
|
||||
databasePath := fp.Join(getHomeDir(), ".shiori.db")
|
||||
if value, found := os.LookupEnv("ENV_SHIORI_DB"); found {
|
||||
// If ENV_SHIORI_DB is directory, append "shiori.db" as filename
|
||||
// If ENV_SHIORI_DB is directory, append ".shiori.db" as filename
|
||||
if f1, err := os.Stat(value); err == nil && f1.IsDir() {
|
||||
value = fp.Join(value, "shiori.db")
|
||||
value = fp.Join(value, ".shiori.db")
|
||||
}
|
||||
|
||||
databasePath = value
|
||||
|
@ -28,6 +29,15 @@ func main() {
|
|||
cmd.Execute()
|
||||
}
|
||||
|
||||
func getHomeDir() string {
|
||||
user, err := user.Current()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return user.HomeDir
|
||||
}
|
||||
|
||||
func checkError(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
Loading…
Reference in New Issue