foodoles/bdd/bdd.go

28 lines
443 B
Go
Raw Normal View History

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