From 5f61857c0f454ffbb790bd95177504d9b16953c0 Mon Sep 17 00:00:00 2001 From: Umputun Date: Thu, 28 Dec 2017 23:07:02 -0600 Subject: [PATCH] extract small prep steps from main --- app/main.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/main.go b/app/main.go index 4404d3db..ebfc6d27 100644 --- a/app/main.go +++ b/app/main.go @@ -57,14 +57,9 @@ func main() { setupLog(opts.Dbg) log.Print("[INFO] started remark") - boltSites := []store.BoltSite{} - for _, site := range opts.Sites { - boltSites = append(boltSites, store.BoltSite{SiteID: site, FileName: fmt.Sprintf("%s/%s.db", opts.BoltPath, site)}) - } - dataStore, err := store.NewBoltDB(boltSites...) - if err != nil { - log.Fatalf("[ERROR] can't initialize data store, %+v", err) - } + makeDirs() + + dataStore := makeBoltStore() if p.Active != nil && p.Command.Find("import") == p.Active { params := migrator.ImportParams{ @@ -118,6 +113,24 @@ func main() { srv.Run() } +// makeBoltStore creates store for all sites +func makeBoltStore() store.Interface { + sites := []store.BoltSite{} + for _, site := range opts.Sites { + sites = append(sites, store.BoltSite{SiteID: site, FileName: fmt.Sprintf("%s/%s.db", opts.BoltPath, site)}) + } + result, err := store.NewBoltDB(sites...) + if err != nil { + log.Fatalf("[ERROR] can't initialize data store, %+v", err) + } + return result +} + +func makeDirs() { + _ = os.MkdirAll(opts.BoltPath, 700) + _ = os.MkdirAll(opts.BackupLocation, 700) +} + func setupLog(dbg bool) { filter := &logutils.LevelFilter{ Levels: []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR"},