play

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGameNotFound    = errors.New("game is not found")
	ErrPartnerNotFound = errors.New("partner is not found")
)

Functions

This section is empty.

Types

type GameStorage

type GameStorage interface {
	// GetGame returns game instance for given gameID from storage. Returns nil
	// when given gameID is not found in database.
	GetGame(ctx context.Context, gameID string) (*entity.Game, error)

	// Save is used for saving game instance in storage.
	SaveGame(ctx context.Context, game entity.Game) error
}

type PartnerStorage

type PartnerStorage interface {
	// GetAvailablePartners returns list of monster that selectable as partner.
	// Returns nil when there is no partners available.
	GetAvailablePartners(ctx context.Context) ([]entity.Monster, error)

	// GetPartner returns partner instance from given partner id. Returns nil
	// when given partnerID is not found.
	GetPartner(ctx context.Context, partnerID string) (*entity.Monster, error)
}

type Service

type Service interface {
	// GetAvailablePartners returns monsters that available to be selected as player partner.
	GetAvailablePartners(ctx context.Context) ([]entity.Monster, error)

	// NewGame is used for initiating new game in storage. If the given `partnerID` not found in storage,
	// it returns `ErrPartnerNotFound`. Upon success it returns game instance that being saved on storage.
	NewGame(ctx context.Context, playerName string, partnerID string) (*entity.Game, error)

	// GetGame returns game instance from storage from given game id. Upon game is not found, it returns
	// `ErrGameNotFound`.
	GetGame(ctx context.Context, gameID string) (*entity.Game, error)
}

func NewService

func NewService(cfg ServiceConfig) (Service, error)

NewService returns new instance of service.

type ServiceConfig

type ServiceConfig struct {
	GameStorage    GameStorage    `validate:"nonnil"`
	PartnerStorage PartnerStorage `validate:"nonnil"`
}

func (ServiceConfig) Validate

func (c ServiceConfig) Validate() error

Jump to

Keyboard shortcuts

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