This commit is contained in:
Jay 2020-04-20 10:24:33 +08:00
parent 97b90146ca
commit 45c6f4ad2f
2 changed files with 16 additions and 3 deletions

View File

@ -32,6 +32,18 @@ func New(dbPath ...string) error {
return err return err
} }
tx, err := db.Begin(true)
if err != nil {
return err
}
if _, err := tx.CreateBucketIfNotExists([]byte("led")); err != nil {
tx.Rollback()
return err
}
tx.Commit()
return nil return nil
} }

View File

@ -2,6 +2,7 @@ package routes
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"rpi-ci-led/pkg/database" "rpi-ci-led/pkg/database"
@ -27,9 +28,9 @@ func SetRoutes(e *gin.Engine) {
var list []string = make([]string, 0) var list []string = make([]string, 0)
db := database.Get() db := database.Get()
err := db.View(func(tx *bbolt.Tx) error { err := db.View(func(tx *bbolt.Tx) error {
bucket, err := tx.CreateBucketIfNotExists([]byte("led")) bucket := tx.Bucket([]byte("led"))
if err != nil { if bucket == nil {
return err return errors.New("bucket not init")
} }
if b := bucket.Get([]byte("project")); b == nil { if b := bucket.Get([]byte("project")); b == nil {
fmt.Println("b ::: ", b) fmt.Println("b ::: ", b)