apiserver

package
v0.0.0-...-2eb796a Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIServer

type APIServer struct {
	ConfigReader
	// contains filtered or unexported fields
}

APIServer is the main object of programm.

func NewAPIServer

func NewAPIServer(runMode string, db Database, router *gin.Engine, logger *zerolog.Logger, configReader ConfigReader) *APIServer

NewAPIServer creates a singleton APIServer object.

func (*APIServer) AcceptGameInvitation

func (apiServer *APIServer) AcceptGameInvitation(c *websocket.Client, jsonData []byte) (*RPCAcceptGameInvitationResponse, error)

func (*APIServer) BoardState

func (app *APIServer) BoardState(c *websocket.Client, jsonData []byte) (*RPCBoardStateResponse, error)

func (*APIServer) CallForGame

func (apiServer *APIServer) CallForGame(c *websocket.Client, jsonData []byte) (*RPCCallForGameResponse, error)

func (*APIServer) DeclineGameInvitation

func (apiServer *APIServer) DeclineGameInvitation(c *websocket.Client, jsonData []byte) (*RPCDeclineGameInvitationResponse, error)

func (*APIServer) FindUsers

func (app *APIServer) FindUsers(_ *websocket.Client, jsonData []byte) (*RPCFindUserResponse, error)

func (*APIServer) GameHistory

func (app *APIServer) GameHistory(_ *websocket.Client, jsonData []byte) (*RPCGameHistoryResponse, error)

func (*APIServer) GetUser

func (apiServer *APIServer) GetUser(c *websocket.Client, jsonData []byte) (*RPCGetUserResponse, error)

func (*APIServer) IsPlaying

func (apiServer *APIServer) IsPlaying(c *websocket.Client, jsonData []byte) (*RPCIsPlayingResponse, error)

func (*APIServer) LeaveGame

func (app *APIServer) LeaveGame(c *websocket.Client, jsonData []byte) (*RPCLeaveGameResponse, error)

func (*APIServer) MakeMove

func (apiServer *APIServer) MakeMove(c *websocket.Client, jsonData []byte) (*RPCMakeMoveResponse, error)

func (*APIServer) OnAlive

func (*APIServer) OnAlive(*websocket.Client)

func (*APIServer) OnConnecting

func (*APIServer) OnDisconect

func (*APIServer) OnMessage

func (*APIServer) OnNotification

func (*APIServer) OnPresence

func (*APIServer) OnRPC

func (apiServer *APIServer) OnRPC(c *websocket.Client, rpc centrifuge.RPCEvent) (centrifuge.RPCReply, error)

func (*APIServer) OnSubscribe

func (*APIServer) OnUnsubscribe

func (*APIServer) PublishEvent

func (apiServer *APIServer) PublishEvent(channel string, event Event) (centrifuge.PublishResult, error)

func (*APIServer) Run

func (a *APIServer) Run() error

Run runs the HTTP server.

func (*APIServer) Top10

func (apiServer *APIServer) Top10(_ *websocket.Client, _ []byte) (*RPCFindUserResponse, error)

type ConfigReader

type ConfigReader interface {
	ReadConfig() (*config.Config, error)
}

ConfigReader is used to read config from multiple sources.

type Database

type Database interface {
	// Create new user.
	CreateUser(username, email, passwordBcrypt string) (*model.User, error)

	// Create new user from oauth.
	CreateUserOauth(username string, email *string, oauthID string, oauthSerivce oauth.Service) (*model.User, error)

	// Get user by login.
	GetUserByLogin(login string) (*model.User, error)

	// Get user by ID.
	GetUserByID(userID int64) (*model.User, error)

	// Create new game.
	CreateGame(blackUserID, whiteUserID int64) (gameID int64, err error)

	// Delete a game.
	DeleteGame(gameID int64) error

	// Get game by id.
	GetGameByID(gameID int64) (*model.Game, error)

	// Get game moves by id.
	GetGameMovesByID(gameID int64) ([]model.Move, error)

	// Create new move.
	CreateMove(gameID, userID int64, x, y int) error

	// Is user a game member?
	IsGameMember(userID, gameID int64) (bool, error)

	// Is user playing a game right now?
	IsPlaying(userID int64) (bool, error)

	// Returns the playing game.
	GetPlayingGame(userID int64) (*model.PlayingGame, error)

	// Find users by username.
	FindUsers(username string) ([]*model.User, error)

	// Get game history by username.
	GameHistory(username string) ([]model.GameHistoryItem, error)

	// Top10 return the top 10 users by ranking.
	Top10() ([]*model.User, error)

	// Delete a game from database.
	DeclineGameInvitation(userID int64, gameID int64) error

	// Set game status to InProgress.
	StartGame(gameID int64) error

	// Set game status to Finished.
	FinishGameWithWinner(gameID, winnerID int64) error

	// Close
	Close() error
}

type Event

type Event interface {
	EventType() string
}

type EventDeclineGameInvitation

type EventDeclineGameInvitation struct{}

func (*EventDeclineGameInvitation) EventType

func (e *EventDeclineGameInvitation) EventType() string

type EventGameEndedInDraw

type EventGameEndedInDraw struct{}

func (*EventGameEndedInDraw) EventType

func (e *EventGameEndedInDraw) EventType() string

type EventGameEndedWithWinner

type EventGameEndedWithWinner struct {
	WinnerID int64 `json:"winner_id"`
}

func (*EventGameEndedWithWinner) EventType

func (e *EventGameEndedWithWinner) EventType() string

type EventGameInvitation

type EventGameInvitation struct {
	GameID    int64     `json:"game_id"`
	Inviter   string    `json:"inviter"`
	InvitedAt time.Time `json:"invited_at"`
}

func (*EventGameInvitation) EventType

func (e *EventGameInvitation) EventType() string

type EventGameInvitationExpired

type EventGameInvitationExpired struct{}

func (*EventGameInvitationExpired) EventType

func (e *EventGameInvitationExpired) EventType() string

type EventGameStarted

type EventGameStarted struct{}

func (*EventGameStarted) EventType

func (e *EventGameStarted) EventType() string

type EventMove

type EventMove struct {
	UserID      int64 `json:"user_id"`
	XCoordinate int   `json:"x_coordinate"`
	YCoordinate int   `json:"y_coordinate"`
}

func (*EventMove) EventType

func (e *EventMove) EventType() string

type EventUserLeftGame

type EventUserLeftGame struct {
	WhoLeftGameID int64  `json:"who_left_game"`
	WinnerID      *int64 `json:"winner_id"`
}

func (*EventUserLeftGame) EventType

func (e *EventUserLeftGame) EventType() string

type RPCAcceptGameInvitationRequest

type RPCAcceptGameInvitationRequest struct {
	GameID int64 `json:"game_id"`
}

type RPCAcceptGameInvitationResponse

type RPCAcceptGameInvitationResponse struct{}

type RPCBoardStateRequest

type RPCBoardStateRequest struct {
	GameID int64 `json:"game_id"`
}

type RPCBoardStateResponse

type RPCBoardStateResponse struct {
	Moves []EventMove `json:"moves"`
}

type RPCCallForGameRequest

type RPCCallForGameRequest struct {
	Username string `json:"username"`
}

type RPCCallForGameResponse

type RPCCallForGameResponse struct {
	GameID int64 `json:"game_id"`
}

type RPCDeclineGameInvitationRequest

type RPCDeclineGameInvitationRequest struct {
	GameID int64 `json:"game_id"`
}

type RPCDeclineGameInvitationResponse

type RPCDeclineGameInvitationResponse struct{}

type RPCFindUserRequest

type RPCFindUserRequest struct {
	Username string `json:"username"`
}

type RPCFindUserResponse

type RPCFindUserResponse struct {
	Users []findUser `json:"users"`
}

type RPCGameHistoryRequest

type RPCGameHistoryRequest struct {
	Username string `json:"username"`
}

type RPCGameHistoryResponse

type RPCGameHistoryResponse struct {
	Games []model.GameHistoryItem `json:"games"`
}

type RPCGetUserRequest

type RPCGetUserRequest struct {
	Username string `json:"username"`
}

type RPCGetUserResponse

type RPCGetUserResponse struct {
	ID       int64   `json:"id"`
	Username string  `json:"username"`
	Email    *string `json:"email,omitempty"`
	Ranking  int     `json:"ranking"`
}

type RPCIsPlayingRequest

type RPCIsPlayingRequest struct{}

type RPCIsPlayingResponse

type RPCIsPlayingResponse struct {
	Game *playingGame `json:"game"`
}

type RPCLeaveGameRequest

type RPCLeaveGameRequest struct {
	GameID int64 `json:"game_id"`
}

type RPCLeaveGameResponse

type RPCLeaveGameResponse struct{}

type RPCMakeMoveRequest

type RPCMakeMoveRequest struct {
	GameID      int64 `json:"game_id"`
	XCoordinate int   `json:"x_coordinate"`
	YCoordinate int   `json:"y_coordinate"`
}

type RPCMakeMoveResponse

type RPCMakeMoveResponse struct{}

type WebsocketSession

type WebsocketSession struct {
	UserID int64 `json:"user_id"`
}

func (*WebsocketSession) Authorized

func (ws *WebsocketSession) Authorized() bool

func (*WebsocketSession) Credentials

func (ws *WebsocketSession) Credentials() *centrifuge.Credentials

Jump to

Keyboard shortcuts

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