summaryrefslogtreecommitdiff
path: root/middleware/session/memstore.go
blob: 2fcef3906827fd5aeb75053f2ad9129c1c5d9342 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
}