From 685fa86ad3d72bb4b9024d0288a9b4210e3224de Mon Sep 17 00:00:00 2001 From: RandomChars <random@chars.jp> Date: Sat, 20 Nov 2021 13:08:01 +0900 Subject: [PATCH] configurable use of different backend implementations --- README.md | 6 +++--- config.go | 2 ++ main.go | 17 +++++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9aba6a5..4022e15 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ Image Board ----------- -Taggable image board in 1272 lines of code. +Taggable image board with multiple backend implementations. Get it: ```shell -go get random.chars.jp/git/image-board +go get random.chars.jp/git/image-board/v2 ``` Client example: @@ -13,7 +13,7 @@ package main import ( "fmt" - "random.chars.jp/git/image-board/client" + "random.chars.jp/git/image-board-client" ) func main() { diff --git a/config.go b/config.go index fe33609..9a1fcfd 100644 --- a/config.go +++ b/config.go @@ -22,6 +22,7 @@ type serverConf struct { type systemConf struct { Verbose bool `toml:"verbose"` + Backend string `toml:"backend"` Store string `toml:"store"` SingleUser bool `toml:"single-user"` Private bool `toml:"private"` @@ -67,6 +68,7 @@ func confLoad() { var defConf = conf{ System: systemConf{ Verbose: false, + Backend: "filesystem", Store: "db", SingleUser: true, Private: false, diff --git a/main.go b/main.go index 2a1a46b..0026fda 100644 --- a/main.go +++ b/main.go @@ -23,14 +23,23 @@ func main() { confLoad() - // TODO: support more backends - instance = filesystem.New(config.System.Store, config.System.Verbose) + var doSuccess func() + switch config.System.Backend { + case "filesystem": + instance = filesystem.New(config.System.Store, config.System.Verbose) + doSuccess = func() { + log.Printf("store path %s revision %v compat %v", + config.System.Store, instance.(*filesystem.Store).Revision, instance.(*filesystem.Store).Compat) + } + default: + log.Fatalf("store backend %s does not exist", config.System.Backend) + } + if err := instance.Open(); err != nil { log.Printf("error opening store: %s", err) return } else { - log.Printf("store path %s revision %v compat %v", - config.System.Store, instance.(*filesystem.Store).Revision, instance.(*filesystem.Store).Compat) + doSuccess() } if info, err := instance.User(instance.UserInitial()); err == nil { -- GitLab