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.

35 lines
676 B
Go

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
}