initial commit
This commit is contained in:
commit
bec2cfd017
18 files changed
+781
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/abelith/gomax/state"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type FSMStorage struct {
|
||||
m sync.Map
|
||||
}
|
||||
|
||||
func NewMemoryFSMStorage() *FSMStorage {
|
||||
return &FSMStorage{}
|
||||
}
|
||||
|
||||
func (f *FSMStorage) Get(_ context.Context, userID int) (*state.Snapshot, error) {
|
||||
st, ok := f.m.Load(userID)
|
||||
if !ok {
|
||||
return nil, state.ErrStateNotFound
|
||||
}
|
||||
|
||||
return st.(*state.Snapshot), nil
|
||||
}
|
||||
|
||||
func (f *FSMStorage) Put(_ context.Context, snapshot *state.Snapshot) error {
|
||||
f.m.Store(snapshot.ID, snapshot)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *FSMStorage) Delete(_ context.Context, snapshot *state.Snapshot) error {
|
||||
f.m.Delete(snapshot.ID)
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user