You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
819 B
Go
40 lines
819 B
Go
2 years ago
|
package manager
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"git.noahlan.cn/northlan/ngs/session"
|
||
|
)
|
||
|
|
||
|
const dataKey = "DATA"
|
||
|
|
||
|
type (
|
||
|
SessionData struct {
|
||
|
LiveRooms []LiveRoom // Session 对应 直播间ID列表
|
||
|
GameType string // 客户端游戏类型
|
||
|
}
|
||
|
|
||
|
DataFilter func(session *session.Session, data *SessionData) bool
|
||
|
)
|
||
|
|
||
|
func NewSessionData(gameType string) *SessionData {
|
||
|
return &SessionData{
|
||
|
LiveRooms: make([]LiveRoom, 0),
|
||
|
GameType: gameType,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func GetSessionData(s *session.Session) (*SessionData, error) {
|
||
|
if !s.HasKey(dataKey) {
|
||
|
return nil, errors.New("session中无data数据")
|
||
|
}
|
||
|
return s.Value(dataKey).(*SessionData), nil
|
||
|
}
|
||
|
|
||
|
func (m *SessionData) AddLiveRoom(room ...LiveRoom) {
|
||
|
m.LiveRooms = append(m.LiveRooms, room...)
|
||
|
}
|
||
|
|
||
|
func (m *SessionData) WithSession(s *session.Session) {
|
||
|
s.Set(dataKey, m)
|
||
|
}
|