-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
57 lines (44 loc) · 876 Bytes
/
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
package gosocket
import (
uuid "github.com/satori/go.uuid"
)
type Session struct {
sID string
uID string
conn *Conn
settings map[string]interface{}
}
func NewSession(conn *Conn) *Session {
id, _ := uuid.NewV4()
session := &Session{
sID: id.String(),
uID: "",
conn: conn,
settings: make(map[string]interface{}),
}
return session
}
func (s *Session) GetSessionID() string {
return s.sID
}
func (s *Session) BindUserID(uid string) {
s.uID = uid
}
func (s *Session) GetUserID() string {
return s.uID
}
func (s *Session) GetConn() *Conn {
return s.conn
}
func (s *Session) SetConn(conn *Conn) {
s.conn = conn
}
func (s *Session) GetSetting(key string) interface{} {
if v, ok := s.settings[key]; ok {
return v
}
return nil
}
func (s *Session) SetSetting(key string, value interface{}) {
s.settings[key] = value
}