2024-09-12 04:30:23 +02:00
|
|
|
package storage
|
2024-09-06 01:40:57 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"git.defalsify.org/vise.git/db"
|
|
|
|
"git.defalsify.org/vise.git/persist"
|
|
|
|
)
|
|
|
|
|
2024-09-21 01:32:39 +02:00
|
|
|
const (
|
|
|
|
DATATYPE_CUSTOM = 128
|
|
|
|
)
|
|
|
|
|
2024-09-06 01:40:57 +02:00
|
|
|
type Storage struct {
|
|
|
|
Persister *persist.Persister
|
|
|
|
UserdataDb db.Db
|
|
|
|
}
|
|
|
|
|
|
|
|
type StorageProvider interface {
|
2024-09-12 17:46:11 +02:00
|
|
|
Get(sessionId string) (*Storage, error)
|
|
|
|
Put(sessionId string, storage *Storage) error
|
2024-09-06 01:40:57 +02:00
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
|
|
|
type SimpleStorageProvider struct {
|
2024-09-12 17:46:11 +02:00
|
|
|
*Storage
|
2024-09-06 01:40:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewSimpleStorageProvider(stateStore db.Db, userdataStore db.Db) StorageProvider {
|
|
|
|
pe := persist.NewPersister(stateStore)
|
2024-09-11 00:09:10 +02:00
|
|
|
pe = pe.WithFlush()
|
2024-09-06 01:40:57 +02:00
|
|
|
return &SimpleStorageProvider{
|
2024-09-12 17:46:11 +02:00
|
|
|
Storage: &Storage{
|
2024-09-06 01:40:57 +02:00
|
|
|
Persister: pe,
|
|
|
|
UserdataDb: userdataStore,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-12 17:46:11 +02:00
|
|
|
func (p *SimpleStorageProvider) Get(sessionId string) (*Storage, error) {
|
2024-09-06 01:40:57 +02:00
|
|
|
return p.Storage, nil
|
|
|
|
}
|
|
|
|
|
2024-09-12 17:46:11 +02:00
|
|
|
func (p *SimpleStorageProvider) Put(sessionId string, storage *Storage) error {
|
2024-09-06 01:40:57 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *SimpleStorageProvider) Close() error {
|
2024-09-10 21:44:10 +02:00
|
|
|
return p.Storage.UserdataDb.Close()
|
2024-09-06 01:40:57 +02:00
|
|
|
}
|