visedriver/storage/storage.go

57 lines
1.2 KiB
Go
Raw Normal View History

2024-09-12 04:30:23 +02:00
package storage
import (
2025-01-19 10:04:37 +01:00
"context"
"git.defalsify.org/vise.git/db"
"git.defalsify.org/vise.git/persist"
)
const (
DATATYPE_EXTEND = 128
)
type Storage struct {
2025-01-21 16:28:55 +01:00
Persister *persist.Persister
UserdataDb db.Db
}
2025-01-19 10:35:09 +01:00
func (s *Storage) Close(ctx context.Context) error {
return s.UserdataDb.Close(ctx)
}
type StorageProvider interface {
Get(ctx context.Context, sessionId string) (*Storage, error)
Put(ctx context.Context, sessionId string, storage *Storage) error
2025-01-19 10:04:37 +01:00
Close(ctx context.Context) error
}
type SimpleStorageProvider struct {
*Storage
}
func NewSimpleStorageProvider(stateStore db.Db, userdataStore db.Db) StorageProvider {
pe := persist.NewPersister(stateStore)
pe = pe.WithFlush()
return &SimpleStorageProvider{
Storage: &Storage{
2025-01-21 16:28:55 +01:00
Persister: pe,
UserdataDb: userdataStore,
},
}
}
func (p *SimpleStorageProvider) Get(ctx context.Context, sessionId string) (*Storage, error) {
p.Storage.UserdataDb.Start(ctx)
return p.Storage, nil
}
func (p *SimpleStorageProvider) Put(ctx context.Context, sessionId string, storage *Storage) error {
storage.UserdataDb.Stop(ctx)
return nil
}
2025-01-19 10:04:37 +01:00
func (p *SimpleStorageProvider) Close(ctx context.Context) error {
2025-01-19 10:35:09 +01:00
return p.Storage.Close(ctx)
}