package manager import ( "errors" "git.noahlan.cn/northlan/ngs/session" ) const ( DataKey = "DATA" ) type DataManager struct { } func NewDataManager() *DataManager { return &DataManager{} } func (m *DataManager) SessionGameStatus(session *session.Session, status GameStatus) { if data, err := m.SessionData(session); err == nil { data.SetStatus(status) } } func (m *DataManager) SetSessionData(s *session.Session, data *Data) { s.Set(DataKey, data) } func (m *DataManager) SessionData(session *session.Session) (*Data, error) { if !session.HasKey(DataKey) { return nil, errors.New("session中无data数据") } return session.Value(DataKey).(*Data), nil }