Documentation ¶
Overview ¶
Package helpers has generic implementations of finicky methods, like Moves(), ListGames() that are appropriate for storage managers who don't get a performance boost from well-crafted queries to use.
Index ¶
- func ListGamesHelper(s AllGamesStorageManager, max int, list listing.Type, userID string, ...) []*extendedgame.CombinedStorageRecord
- func MovesHelper(s boardgame.StorageManager, gameID string, fromVersion, toVersion int) ([]*boardgame.MoveStorageRecord, error)
- type AllGamesStorageManager
- type ExtendedMemoryStorageManager
- func (s *ExtendedMemoryStorageManager) AgentState(gameID string, player boardgame.PlayerIndex) ([]byte, error)
- func (s *ExtendedMemoryStorageManager) CleanUp()
- func (s *ExtendedMemoryStorageManager) Close()
- func (s *ExtendedMemoryStorageManager) CombinedGame(id string) (*extendedgame.CombinedStorageRecord, error)
- func (s *ExtendedMemoryStorageManager) Connect(config string) error
- func (s *ExtendedMemoryStorageManager) ConnectCookieToUser(cookie string, user *users.StorageRecord) error
- func (s *ExtendedMemoryStorageManager) ExtendedGame(id string) (*extendedgame.StorageRecord, error)
- func (s *ExtendedMemoryStorageManager) FetchInjectedDataForGame(gameID string, dataType string) interface{}
- func (s *ExtendedMemoryStorageManager) GetUserByCookie(cookie string) *users.StorageRecord
- func (s *ExtendedMemoryStorageManager) GetUserByID(uid string) *users.StorageRecord
- func (s *ExtendedMemoryStorageManager) PlayerMoveApplied(game *boardgame.GameStorageRecord) error
- func (s *ExtendedMemoryStorageManager) SaveAgentState(gameID string, player boardgame.PlayerIndex, state []byte) error
- func (s *ExtendedMemoryStorageManager) SetPlayerForGame(gameID string, playerIndex boardgame.PlayerIndex, userID string) error
- func (s *ExtendedMemoryStorageManager) UpdateExtendedGame(id string, eGame *extendedgame.StorageRecord) error
- func (s *ExtendedMemoryStorageManager) UpdateUser(user *users.StorageRecord) error
- func (s *ExtendedMemoryStorageManager) UserIDsForGame(gameID string) []string
- func (s *ExtendedMemoryStorageManager) WithManagers(managers []*boardgame.GameManager)
- type GameChecker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListGamesHelper ¶
func ListGamesHelper(s AllGamesStorageManager, max int, list listing.Type, userID string, gameType string) []*extendedgame.CombinedStorageRecord
ListGamesHelper is an implementation for ListGames() if the underlying storage manager can't do any better than walking through each game anyway. Note that your StorageManager must implement AllGames().
func MovesHelper ¶
func MovesHelper(s boardgame.StorageManager, gameID string, fromVersion, toVersion int) ([]*boardgame.MoveStorageRecord, error)
MovesHelper is an implementation for Moves() if the underlying storage manager can't do any better than just repeated calls to Move() anyway.
Types ¶
type AllGamesStorageManager ¶
type AllGamesStorageManager interface { api.StorageManager //AllGames simply returns all games AllGames() []*boardgame.GameStorageRecord }
AllGamesStorageManager wraps normal storage manager but also has an AllGames method.
type ExtendedMemoryStorageManager ¶
type ExtendedMemoryStorageManager struct {
// contains filtered or unexported fields
}
ExtendedMemoryStorageManager implements the ExtendedGame methods (i.e the methods in server.StorageManager) in memory. Designed to be embedded anonymously in the containing item. Get a new one from NewExtendedMemoryStorageManager.
func NewExtendedMemoryStorageManager ¶
func NewExtendedMemoryStorageManager(checker GameChecker) *ExtendedMemoryStorageManager
NewExtendedMemoryStorageManager returns a new extended memory storage manager. Checker is generally the storage manager you're embedded in.
func (*ExtendedMemoryStorageManager) AgentState ¶
func (s *ExtendedMemoryStorageManager) AgentState(gameID string, player boardgame.PlayerIndex) ([]byte, error)
AgentState implements the AgentState part of the interface.
func (*ExtendedMemoryStorageManager) CleanUp ¶
func (s *ExtendedMemoryStorageManager) CleanUp()
CleanUp is a no op
func (*ExtendedMemoryStorageManager) Close ¶
func (s *ExtendedMemoryStorageManager) Close()
Close is a no op
func (*ExtendedMemoryStorageManager) CombinedGame ¶
func (s *ExtendedMemoryStorageManager) CombinedGame(id string) (*extendedgame.CombinedStorageRecord, error)
CombinedGame implements that part of the server interface.
func (*ExtendedMemoryStorageManager) Connect ¶
func (s *ExtendedMemoryStorageManager) Connect(config string) error
Connect is a no op
func (*ExtendedMemoryStorageManager) ConnectCookieToUser ¶
func (s *ExtendedMemoryStorageManager) ConnectCookieToUser(cookie string, user *users.StorageRecord) error
ConnectCookieToUser implements that part of the server storage interface. If user is nil, the cookie should be deleted if it exists. If the user does not yet exist, it should be added to the database.
func (*ExtendedMemoryStorageManager) ExtendedGame ¶
func (s *ExtendedMemoryStorageManager) ExtendedGame(id string) (*extendedgame.StorageRecord, error)
ExtendedGame will return extendedgame.DefaultStorageRecord() if the associated game exists.
func (*ExtendedMemoryStorageManager) FetchInjectedDataForGame ¶
func (s *ExtendedMemoryStorageManager) FetchInjectedDataForGame(gameID string, dataType string) interface{}
FetchInjectedDataForGame can just return nil
func (*ExtendedMemoryStorageManager) GetUserByCookie ¶
func (s *ExtendedMemoryStorageManager) GetUserByCookie(cookie string) *users.StorageRecord
GetUserByCookie implements that part of the server storage interface.
func (*ExtendedMemoryStorageManager) GetUserByID ¶
func (s *ExtendedMemoryStorageManager) GetUserByID(uid string) *users.StorageRecord
GetUserByID implements that part of the server storage interface.
func (*ExtendedMemoryStorageManager) PlayerMoveApplied ¶
func (s *ExtendedMemoryStorageManager) PlayerMoveApplied(game *boardgame.GameStorageRecord) error
PlayerMoveApplied is a no op
func (*ExtendedMemoryStorageManager) SaveAgentState ¶
func (s *ExtendedMemoryStorageManager) SaveAgentState(gameID string, player boardgame.PlayerIndex, state []byte) error
SaveAgentState implements that part of the StorageManager interface.
func (*ExtendedMemoryStorageManager) SetPlayerForGame ¶
func (s *ExtendedMemoryStorageManager) SetPlayerForGame(gameID string, playerIndex boardgame.PlayerIndex, userID string) error
SetPlayerForGame implemnts that part of the server storage interface.
func (*ExtendedMemoryStorageManager) UpdateExtendedGame ¶
func (s *ExtendedMemoryStorageManager) UpdateExtendedGame(id string, eGame *extendedgame.StorageRecord) error
UpdateExtendedGame implements that part of the server storage interface
func (*ExtendedMemoryStorageManager) UpdateUser ¶
func (s *ExtendedMemoryStorageManager) UpdateUser(user *users.StorageRecord) error
UpdateUser stores or update all fields
func (*ExtendedMemoryStorageManager) UserIDsForGame ¶
func (s *ExtendedMemoryStorageManager) UserIDsForGame(gameID string) []string
UserIDsForGame implements that part of the server storage interface.
func (*ExtendedMemoryStorageManager) WithManagers ¶
func (s *ExtendedMemoryStorageManager) WithManagers(managers []*boardgame.GameManager)
WithManagers is a no op
type GameChecker ¶
type GameChecker interface {
Game(gameID string) (*boardgame.GameStorageRecord, error)
}
GameChecker is just one meethod to fetch a Game given an ID. It's typically just the storage manager you're embedded in but can be other objects in other cases, thus why it's split out separately.