clong

package
v0.0.0-...-32bdb9f Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseService

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

BaseService is a messaging hub.

func NewService

func NewService(scores ScoreStore) *BaseService

NewService creates a new service.

func (*BaseService) PublishControl

func (s *BaseService) PublishControl(ctx context.Context, ctrl Control)

PublishControl publishes a control to the messaging bus.

func (*BaseService) PublishEvent

func (s *BaseService) PublishEvent(_ context.Context, event Event)

PublishEvent publishes an event to the messaging bus.

func (*BaseService) RegisterController

func (s *BaseService) RegisterController(c ClientConnection)

RegisterController registers a new controller.

func (*BaseService) RegisterScreen

func (s *BaseService) RegisterScreen(c ClientConnection)

RegisterScreen registers a new screen.

func (*BaseService) UnregisterController

func (s *BaseService) UnregisterController(c ClientConnection)

UnregisterController removes a controller.

func (*BaseService) UnregisterScreen

func (s *BaseService) UnregisterScreen(c ClientConnection)

UnregisterScreen removes a screen.

type ClientConnection

type ClientConnection interface {
	WriteJSON(v any) error
	Close() error
}

ClientConnection is a connection with a client.

type Control

type Control struct {
	Type       string  `json:"type"`
	Player     User    `json:"player"`
	Color      string  `json:"color"`
	PosX       float64 `json:"posX"`
	PosY       float64 `json:"posY"`
	VelocityX  float64 `json:"velocityX"`
	VelocityY  float64 `json:"velocityY"`
	FinalScore int64   `json:"finalScore"`
}

Control is a message sent from a controller.

type Event

type Event struct {
	Type   string `json:"type"`
	Player User   `json:"player"`
	Points int64  `json:"points"`
}

Event is a message sent to a controller.

type Score

type Score struct {
	ID         string `json:"id"`
	Player     User   `json:"player"`
	FinalScore int64  `json:"finalScore"`
	Color      string `json:"color"`
}

Score is a score of a player.

type ScoreStore

type ScoreStore interface {
	ListAll(ctx context.Context) ([]*Score, error)
	Add(ctx context.Context, scr *Score) error
	RemoveAll(ctx context.Context) error
}

ScoreStore is a store of scores.

type Service

type Service interface {
	RegisterScreen(screen ClientConnection)
	UnregisterScreen(screen ClientConnection)
	RegisterController(controller ClientConnection)
	UnregisterController(controller ClientConnection)
	PublishEvent(ctx context.Context, event Event)
	PublishControl(ctx context.Context, ctrl Control)
}

Service is a messaging hub for events.

type User

type User struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

User is a person who interacts with the app.

Directories

Path Synopsis
Package mysql allows to interact with a MySQL database.
Package mysql allows to interact with a MySQL database.
Package pg allows to interact with a PostgreSQL database.
Package pg allows to interact with a PostgreSQL database.

Jump to

Keyboard shortcuts

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