-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
executable file
·59 lines (50 loc) · 1.2 KB
/
session.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 gweb
import (
"net/url"
"sync"
)
var Sessions = &SessionSafeMap{}
type SessionSafeMap struct {
//sync.RWMutex
_data sync.Map
}
type Session struct {
//sync.RWMutex
ID string
Token string
Attributes *Attributes
CreateTime int64
LastOperationTime int64
LastRequestURL *url.URL
}
func (s *SessionSafeMap) DeleteSession(GLSESSIONID string) {
//s.Lock()
//defer s.Unlock()
//delete(s.Data, k)
//db.NotifyAll(&db.Message{db.Socket_Type_2_STC,k})
s._data.Delete(GLSESSIONID)
}
func (s *SessionSafeMap) AddSession(GLSESSIONID string, session *Session) {
//s.Lock()
//defer s.Unlock()
/*if s.Data==nil{
s.Data=make(map[string]*Session)
}
s.Data[GLSESSIONID] = session*/
//db.NotifyAll(&db.Message{db.Socket_Type_1_STC,session})
s._data.Store(GLSESSIONID, session)
}
func (s *SessionSafeMap) Range(f func(key, value interface{}) bool) {
s._data.Range(f)
}
func (s *SessionSafeMap) GetSession(GLSESSIONID string) *Session {
//s.RLock()
//defer s.RUnlock()
session, ok := s._data.Load(GLSESSIONID)
if !ok {
return nil
}
//session := s.Data[GLSESSIONID]
//db.NotifyAll(&db.Message{db.Socket_Type_1_STC,session})
return session.(*Session)
}