extract small prep steps from main

This commit is contained in:
Umputun
2017-12-28 23:07:02 -06:00
parent df6a0b0593
commit 5f61857c0f
+21 -8
View File
@@ -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"},