-
Notifications
You must be signed in to change notification settings - Fork 10
/
session_manager.go
43 lines (36 loc) · 832 Bytes
/
session_manager.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
package main
import (
"aim-oscar/oscar"
"sync"
)
// SessionManager maps screen names to user sessions
type SessionManager struct {
sessions map[string]*oscar.Session
mutex *sync.RWMutex
}
func NewSessionManager() *SessionManager {
sm := &SessionManager{
sessions: make(map[string]*oscar.Session),
mutex: &sync.RWMutex{},
}
return sm
}
func (sm *SessionManager) SetSession(screen_name string, session *oscar.Session) {
sm.mutex.Lock()
sm.sessions[screen_name] = session
sm.mutex.Unlock()
}
func (sm *SessionManager) GetSession(screen_name string) *oscar.Session {
sm.mutex.RLock()
s, ok := sm.sessions[screen_name]
sm.mutex.RUnlock()
if ok {
return s
}
return nil
}
func (sm *SessionManager) RemoveSession(screen_name string) {
sm.mutex.Lock()
sm.sessions[screen_name] = nil
sm.mutex.Unlock()
}