summaryrefslogtreecommitdiff
path: root/middleware/session/memstore.go
diff options
context:
space:
mode:
Diffstat (limited to 'middleware/session/memstore.go')
-rw-r--r--middleware/session/memstore.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/middleware/session/memstore.go b/middleware/session/memstore.go
new file mode 100644
index 0000000..2fcef39
--- /dev/null
+++ b/middleware/session/memstore.go
@@ -0,0 +1,31 @@
+package session
+
+import (
+ "context"
+ "sync"
+)
+
+type MemoryStore struct {
+ store sync.Map
+}
+
+func (s *MemoryStore) Load(ctx context.Context, sessionID string) Value {
+ val, ok := s.store.Load(sessionID)
+ if ok {
+ return val.(Value)
+ }
+
+ return Value{}
+}
+
+func (s *MemoryStore) Save(ctx context.Context, sessionID string, value Value) error {
+ s.store.Store(sessionID, value)
+
+ return nil
+}
+
+func (s *MemoryStore) Remove(ctx context.Context, sessionID string) error {
+ s.store.Delete(sessionID)
+
+ return nil
+}