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
}
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
}

View File

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