Add configurable path to database and docker-compose sample

This commit is contained in:
Justin Hawkins 2022-05-28 19:28:18 +09:30
parent 49288a5b8b
commit 37e3a3fe7c
4 changed files with 31 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"flag"
"log"
"github.com/tardisx/linkwallet/db"
@ -10,8 +11,19 @@ import (
func main() {
var dbPath string
flag.StringVar(&dbPath, "db-path", "", "path to the database file")
flag.Parse()
if dbPath == "" {
log.Fatal("You need to specify the path to the database file with -db-path")
}
dbh := db.DB{}
dbh.Open("badger")
err := dbh.Open(dbPath)
if err != nil {
log.Fatal(err)
}
bmm := db.NewBookmarkManager(&dbh)
cmm := db.NewConfigManager(&dbh)

View File

@ -1,6 +1,7 @@
package db
import (
"fmt"
"log"
"github.com/tardisx/linkwallet/entity"
@ -11,16 +12,16 @@ type DB struct {
store *bolthold.Store
}
func (db *DB) Open(dir string) {
func (db *DB) Open(path string) error {
// options := bolthold.DefaultOptions
// options.Dir = dir
// options.ValueDir = dir
store, err := bolthold.Open("bolt.db", 0666, nil)
store, err := bolthold.Open(path, 0666, nil)
if err != nil {
panic(err)
return fmt.Errorf("cannot open '%s' - %s", path, err)
}
db.store = store
return nil
}
func (db *DB) Close() {

12
docker-compose.yml-sample Normal file
View File

@ -0,0 +1,12 @@
---
version: "2.1"
services:
linkwallet:
image: tardisx/linkwallet:latest
container_name: linkwallet
command: /app/linkwallet -db-path=/data/linkwallet.db
volumes:
- /home/username/.linkwallet:/data
ports:
- 8109:8080
restart: unless-stopped

View File

@ -8,7 +8,7 @@ import (
"golang.org/x/mod/semver"
)
const Tag = "v0.0.11"
const Tag = "v0.0.12"
var versionInfo struct {
Local struct {