Documentation
¶
Index ¶
- func FromState(timers entity.Timers, Started bool, GameEndReason int, p0id, p1id uint, ...) (*entity.Game, error)
- type Cache
- func (c *Cache) Create(ctx context.Context, game *entity.Game) error
- func (c *Cache) Exists(ctx context.Context, id string) bool
- func (c *Cache) Get(ctx context.Context, id string) (*entity.Game, error)
- func (c *Cache) ListActive(ctx context.Context) ([]*pb.GameMeta, error)
- func (c *Cache) Set(ctx context.Context, game *entity.Game) error
- func (c *Cache) SetGameEventChan(ch chan<- *entity.EventWrapper)
- func (c *Cache) Unload(ctx context.Context, id string)
- type DBStore
- func (s *DBStore) Create(ctx context.Context, g *entity.Game) error
- func (s *DBStore) Disconnect()
- func (s *DBStore) Get(ctx context.Context, id string) (*entity.Game, error)
- func (s *DBStore) ListActive(ctx context.Context) ([]*pb.GameMeta, error)
- func (s *DBStore) Set(ctx context.Context, g *entity.Game) error
- func (s *DBStore) SetGameEventChan(c chan<- *entity.EventWrapper)
- type MemoryStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromState ¶
func FromState(timers entity.Timers, Started bool, GameEndReason int, p0id, p1id uint, WinnerIdx, LoserIdx int, reqBytes, histBytes []byte, stats *entity.Stats, gameEventChan chan<- *entity.EventWrapper, cfg *config.Config) (*entity.Game, error)
FromState returns an entity.Game from a DB State.
Types ¶
type Cache ¶
Cache will reside in-memory, and will be per-node. If we add more nodes we will need to make sure only the right nodes respond to game requests.
func (*Cache) Get ¶
Get gets a game from the cache. It doesn't try to get it from the backing store, if it can't find it in the cache.
func (*Cache) Set ¶
Set sets a game in the cache, AND in the backing store. This ensures if the node crashes the game doesn't just vanish.
func (*Cache) SetGameEventChan ¶
func (c *Cache) SetGameEventChan(ch chan<- *entity.EventWrapper)
SetGameEventChan sets the game event channel to the passed in channel.
type DBStore ¶
type DBStore struct {
// contains filtered or unexported fields
}
DBStore is a postgres-backed store for games.
func NewDBStore ¶
NewDBStore creates a new DB store for games.
func (*DBStore) Disconnect ¶
func (s *DBStore) Disconnect()
func (*DBStore) Get ¶
Get creates an instantiated entity.Game from the database. This function should almost never be called during a live game. The db store should be wrapped with a cache. Only API nodes that have this game in its cache should respond to requests.
func (*DBStore) ListActive ¶
func (*DBStore) Set ¶
Set takes in a game entity that _already exists_ in the DB, and writes it to the database.
func (*DBStore) SetGameEventChan ¶
func (s *DBStore) SetGameEventChan(c chan<- *entity.EventWrapper)
SetGameEventChan sets the game event channel to the passed in channel.
type MemoryStore ¶
MemoryStore is a purely in-memory store of a game. In the real final implementation, we will probably use a Postgres-backed memory store. Due to the nature of this app, we will always need to have a persistent in-memory instantiation of a game.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
func (*MemoryStore) Create ¶
Create creates a game in the store initially. Make it the same function as Set essentially.