diff --git a/db.go b/db.go index 0460467..5b1c213 100644 --- a/db.go +++ b/db.go @@ -43,6 +43,8 @@ type WikiData struct { } func hasPassword(title string) (bool, error) { + Open(RuntimeArgs.DatabaseLocation) + defer Close() title = strings.ToLower(title) if !open { return false, fmt.Errorf("db must be opened before loading") @@ -79,6 +81,8 @@ func hasPassword(title string) (bool, error) { } func getCurrentText(title string, version int) (string, []versionsInfo, bool, time.Duration, bool) { + Open(RuntimeArgs.DatabaseLocation) + defer Close() title = strings.ToLower(title) var vi []versionsInfo totalTime := time.Now().Sub(time.Now()) @@ -122,6 +126,8 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool, ti } func (p *WikiData) load(title string) error { + Open(RuntimeArgs.DatabaseLocation) + defer Close() title = strings.ToLower(title) if !open { return fmt.Errorf("db must be opened before loading!") @@ -156,6 +162,8 @@ func (p *WikiData) load(title string) error { } func (p *WikiData) save(newText string) error { + Open(RuntimeArgs.DatabaseLocation) + defer Close() if !open { return fmt.Errorf("db must be opened before saving") } diff --git a/main.go b/main.go index 8afbb38..f9a128e 100644 --- a/main.go +++ b/main.go @@ -73,10 +73,9 @@ Options:`) } RuntimeArgs.SourcePath = cwd - Open(RuntimeArgs.DatabaseLocation) - defer Close() - // create programdata bucket + Open(RuntimeArgs.DatabaseLocation) + err := db.Update(func(tx *bolt.Tx) error { _, err := tx.CreateBucketIfNotExists([]byte("programdata")) if err != nil { @@ -87,7 +86,8 @@ Options:`) if err != nil { panic(err) } - + Close() + // Default page aboutFile, _ := ioutil.ReadFile(path.Join(RuntimeArgs.SourcePath, "templates/aboutpage.md")) p := WikiData{"help", "", []string{}, []string{}, false}