store

package
v0.0.0-...-ec02fb1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Pacage store includes all the methods for persisting rock paper scissors games

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UpdateGameFromItem

func UpdateGameFromItem(g *game.Game, gi *GameItem)

GameFromItem updates a game struct populated with data from the Dynamo GameItem

func UpdateItemFromGame

func UpdateItemFromGame(gi *GameItem, g *game.Game)

UpdateItemFromGame updates a dynamo game item from the game struct

Types

type GameItem

type GameItem struct {
	PK      string
	SK      string
	Type    string
	Round   int
	Plays   int
	Players map[string]PlayerItem
	GameID  string
	Expires int64
}

GameItem is for game status items

type GameStore

type GameStore interface {
	Load(string) (*game.Game, error)
	StoreAll(*game.Game) error
	StoreRound(*game.Game) error
	StorePlay(*game.GameContext) error
	StorePlayer(*game.GameContext) error
}

GameStore interface declares the

type PlayerItem

type PlayerItem struct {
	ID      string
	Address string
	Play    string
	Round   int
	Score   int
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store stores the dynamo client and other metadata needed, like the table

func New

func New(d *dynamodb.DynamoDB, tableName string) *Store

New creates a dynamo store

func (*Store) Load

func (s *Store) Load(gameID string) (*game.Game, error)

Load returns a populated game based on a gameID, or error if no game exists

func (*Store) StoreAll

func (s *Store) StoreAll(g *game.Game) error

StoreAll takes a Game and persists the entire thing Useful when creating a new game or large operations like round updates

func (*Store) StorePlay

func (s *Store) StorePlay(gc *game.GameContext) error

StorePlay takes a GameContext and stores the bits needed if a play has been made It updates the Game with the current status as well

func (*Store) StorePlayer

func (s *Store) StorePlayer(gc *game.GameContext) error

StorePlayer takes a GameContext and stores the bits needed for an added player

func (*Store) StoreRound

func (s *Store) StoreRound(g *game.Game) error

StoreRound takes a Game and stores the next round For now takes a tiny risk of a race condition updating non-essential data, by uploading the whole item. (e.g. could blow out another player's connection if it changed at the exact wrong time.)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL