summaryrefslogtreecommitdiffhomepage
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/main.go b/main.go
index 69a3772..8d6d402 100644
--- a/main.go
+++ b/main.go
@@ -4,6 +4,7 @@ import (
"fmt"
"os"
+ bolt "go.etcd.io/bbolt"
"github.com/go-redis/redis/v7"
"github.com/valyala/fasthttp"
"toast.cafe/x/brpaste/v2/http"
@@ -15,6 +16,7 @@ var s settings
type settings struct {
Bind string
+ Bolt string
Redis string
Storage string
}
@@ -23,8 +25,9 @@ func main() {
// ---- Flags
ops := &libuconf.OptionSet{AppName: "brpaste"}
ops.StringVar(&s.Bind, "bind", ":8080", "address to bind to")
+ ops.StringVar(&s.Bolt, "bolt", "brpaste.db", "bolt database file to use")
ops.StringVar(&s.Redis, "redis", "redis://localhost:6379", "redis connection string")
- ops.StringVar(&s.Storage, "storage", "redis", "type of storage to use")
+ ops.StringVar(&s.Storage, "storage", "bolt", "type of storage to use")
ops.ParseEnv()
ops.ParseFlags(os.Args[1:])
@@ -42,6 +45,18 @@ func main() {
}
client := redis.NewClient(redisOpts)
store = (*storage.Redis)(client)
+ case "bolt":
+ db, err := bolt.Open(s.Bolt, 0600, nil)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Failed to open/create boltdb database at %s\n", s.Bolt)
+ os.Exit(1)
+ }
+ store, err = storage.OpenBolt(db)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Failed to initialize boltdb database at %s: %s\n", s.Bolt, err)
+ os.Exit(1)
+ }
+ defer db.Close()
default:
fmt.Fprintf(os.Stderr, "Could not figure out which storage system to use, tried %s\n", s.Storage)
os.Exit(1)