Initial Commit

This commit is contained in:
Florian Sylvain
2025-05-02 01:30:37 +02:00
commit e6f9e96c8f
8 changed files with 369 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
package store
import (
"log"
"sync"
"github.com/dgraph-io/badger/v4"
)
var (
db *badger.DB
once sync.Once
dbPath = "./data"
)
func InitDB() {
once.Do(func() {
opts := badger.DefaultOptions(dbPath).WithLogger(nil)
var err error
db, err = badger.Open(opts)
if err != nil {
log.Fatal(err)
}
})
}
func CloseDB() {
if db != nil {
db.Close()
}
}
func GetDB() *badger.DB {
return db
}