-
Notifications
You must be signed in to change notification settings - Fork 60
/
session.go
66 lines (53 loc) · 1.12 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
60
61
62
63
64
65
66
package zero
import (
uuid "github.com/satori/go.uuid"
)
// Session struct
type Session struct {
sID string
uID string
conn *Conn
settings map[string]interface{}
}
// NewSession create a new session
func NewSession(conn *Conn) *Session {
id, _ := uuid.NewV4()
session := &Session{
sID: id.String(),
uID: "",
conn: conn,
settings: make(map[string]interface{}),
}
return session
}
// GetSessionID get session ID
func (s *Session) GetSessionID() string {
return s.sID
}
// BindUserID bind a user ID to session
func (s *Session) BindUserID(uid string) {
s.uID = uid
}
// GetUserID get user ID
func (s *Session) GetUserID() string {
return s.uID
}
// GetConn get zero.Conn pointer
func (s *Session) GetConn() *Conn {
return s.conn
}
// SetConn set a zero.Conn to session
func (s *Session) SetConn(conn *Conn) {
s.conn = conn
}
// GetSetting get setting
func (s *Session) GetSetting(key string) interface{} {
if v, ok := s.settings[key]; ok {
return v
}
return nil
}
// SetSetting set setting
func (s *Session) SetSetting(key string, value interface{}) {
s.settings[key] = value
}