-
Notifications
You must be signed in to change notification settings - Fork 13
/
store.go
59 lines (48 loc) · 1.02 KB
/
store.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package fasthttpsession
import (
"github.com/valyala/fasthttp"
)
// session store struct
type SessionStore interface {
Save(*fasthttp.RequestCtx) error
Get(key string) interface{}
GetAll() map[string]interface{}
Set(key string, value interface{})
Delete(key string)
Flush()
GetSessionId() string
}
type Store struct {
sessionId string
data *CCMap
}
// init store data and sessionId
func (s *Store) Init(sessionId string, data map[string]interface{}) {
s.sessionId = sessionId
s.data = NewDefaultCCMap()
s.data.MSet(data)
}
// get data by key
func (s *Store) Get(key string) interface{} {
return s.data.Get(key)
}
// get all data
func (s *Store) GetAll() map[string]interface{} {
return s.data.GetAll()
}
// set data
func (s *Store) Set(key string, value interface{}) {
s.data.Set(key, value)
}
// delete data by key
func (s *Store) Delete(key string) {
s.data.Delete(key)
}
// flush all data
func (s *Store) Flush() {
s.data.Clear()
}
// get session id
func (s *Store) GetSessionId() string {
return s.sessionId
}