package manager import ( "errors" "git.noahlan.cn/northlan/ngs/session" ) type DataManager struct { } func NewDataManager() *DataManager { return &DataManager{} } func (m *DataManager) SessionGameStatus(session *session.Session, status GameStatus) GameStatus { if data, err := m.SessionData(session); err != nil { return GameEnded } else { return data.SetStatus(status) } } func (m *DataManager) SessionData(session *session.Session) (*GameData, error) { if !session.HasKey(DataKey) { return nil, errors.New("session中无data数据") } return session.Value(DataKey).(*GameData), nil } func (m *DataManager) BattleIdBySession(session *session.Session) int64 { data, err := m.SessionData(session) if err != nil { return 0 } return data.BattleId() }