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