From 159acf2ebbe6688f4f24deedc3e9ca4880a63b3b Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 10 Jan 2017 11:16:03 -0800 Subject: pulling db connection creation into package init not exported Init() initialization func --- system/db/init.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'system/db/init.go') diff --git a/system/db/init.go b/system/db/init.go index 6bc4753..e85304c 100644 --- a/system/db/init.go +++ b/system/db/init.go @@ -13,6 +13,14 @@ import ( var store *bolt.DB +func init() { + var err error + store, err = bolt.Open("system.db", 0666, nil) + if err != nil { + log.Fatalln(err) + } +} + // Close exports the abillity to close our db file. Should be called with defer // after call to Init() from the same place. func Close() { @@ -24,13 +32,7 @@ func Close() { // Init creates a db connection, initializes db with required info, sets secrets func Init() { - var err error - store, err = bolt.Open("system.db", 0666, nil) - if err != nil { - log.Fatalln(err) - } - - err = store.Update(func(tx *bolt.Tx) error { + err := store.Update(func(tx *bolt.Tx) error { // initialize db with all content type buckets & sorted bucket for type for t := range item.Types { _, err := tx.CreateBucketIfNotExists([]byte(t)) -- cgit v1.2.3