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) }