mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-20 01:10:44 +00:00
Use msgpack instead of gob; Added data persistance for badger data store
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user