forked from phachon/fasthttpsession
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
42 lines (35 loc) · 935 Bytes
/
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
package mysql
import (
"github.com/phachon/fasthttpsession"
"github.com/valyala/fasthttp"
"time"
)
// session mysql store
// new default mysql store
func NewMysqlStore(sessionId string) *Store {
mysqlStore := &Store{}
mysqlStore.Init(sessionId, make(map[string]interface{}))
return mysqlStore
}
// new mysql store data
func NewMysqlStoreData(sessionId string, data map[string]interface{}) *Store {
mysqlStore := &Store{}
mysqlStore.Init(sessionId, data)
return mysqlStore
}
type Store struct {
fasthttpsession.Store
}
// save store
func (ms *Store) Save(ctx *fasthttp.RequestCtx) error {
b, err := provider.config.SerializeFunc(ms.GetAll())
if err != nil {
return err
}
session, err := provider.sessionDao.getSessionBySessionId(ms.GetSessionId())
if err != nil || len(session) == 0 {
return nil
}
_, err = provider.sessionDao.updateBySessionId(ms.GetSessionId(), string(b), time.Now().Unix())
return err
}