foodoles/bdd/bdd.go

28 lines
443 B
Go

package bdd
import (
"fmt"
"log"
bolt "go.etcd.io/bbolt"
)
// BDD_VOTES est le nom de la base
var BDD_VOTES = "VotesBucket"
// InitBDD initialise la BDD
func InitBDD() {
db, err := bolt.Open("foods.db", 0600, nil)
if err != nil {
log.Fatal(err)
}
db.Update(func(tx *bolt.Tx) error {
_, err := tx.CreateBucketIfNotExists([]byte(BDD_VOTES))
if err != nil {
return fmt.Errorf("create bucket: %s", err)
}
return nil
})
}