Add configurable path to database and docker-compose sample
This commit is contained in:
parent
49288a5b8b
commit
37e3a3fe7c
@ -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)
|
||||
|
||||
|
9
db/db.go
9
db/db.go
@ -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
12
docker-compose.yml-sample
Normal 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
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user