Use msgpack instead of gob; Added data persistance for badger data store

This commit is contained in:
Pijus Kamandulis
2025-03-13 23:59:07 +02:00
parent 5fe60d831a
commit 97eea30c97
8 changed files with 43 additions and 24 deletions

View File

@@ -1,8 +1,6 @@
package badgerdatastore
import (
"encoding/gob"
"github.com/dgraph-io/badger/v4"
"github.com/pikami/cosmium/internal/logger"
)
@@ -11,10 +9,15 @@ type BadgerDataStore struct {
db *badger.DB
}
func NewBadgerDataStore() *BadgerDataStore {
gob.Register([]interface{}{})
type BadgerDataStoreOptions struct {
PersistDataFilePath string
}
badgerOpts := badger.DefaultOptions("").WithInMemory(true)
func NewBadgerDataStore(options BadgerDataStoreOptions) *BadgerDataStore {
badgerOpts := badger.DefaultOptions(options.PersistDataFilePath)
if options.PersistDataFilePath == "" {
badgerOpts = badgerOpts.WithInMemory(true)
}
db, err := badger.Open(badgerOpts)
if err != nil {