Documentation
¶
Index ¶
- type APIServer
- func (apiServer *APIServer) AcceptGameInvitation(c *websocket.Client, jsonData []byte) (*RPCAcceptGameInvitationResponse, error)
- func (app *APIServer) BoardState(c *websocket.Client, jsonData []byte) (*RPCBoardStateResponse, error)
- func (apiServer *APIServer) CallForGame(c *websocket.Client, jsonData []byte) (*RPCCallForGameResponse, error)
- func (apiServer *APIServer) DeclineGameInvitation(c *websocket.Client, jsonData []byte) (*RPCDeclineGameInvitationResponse, error)
- func (app *APIServer) FindUsers(_ *websocket.Client, jsonData []byte) (*RPCFindUserResponse, error)
- func (app *APIServer) GameHistory(_ *websocket.Client, jsonData []byte) (*RPCGameHistoryResponse, error)
- func (apiServer *APIServer) GetUser(c *websocket.Client, jsonData []byte) (*RPCGetUserResponse, error)
- func (apiServer *APIServer) IsPlaying(c *websocket.Client, jsonData []byte) (*RPCIsPlayingResponse, error)
- func (app *APIServer) LeaveGame(c *websocket.Client, jsonData []byte) (*RPCLeaveGameResponse, error)
- func (apiServer *APIServer) MakeMove(c *websocket.Client, jsonData []byte) (*RPCMakeMoveResponse, error)
- func (*APIServer) OnAlive(*websocket.Client)
- func (apiServer *APIServer) OnConnecting(_ *centrifuge.Node, e centrifuge.ConnectEvent) (websocket.Session, centrifuge.ConnectReply, error)
- func (*APIServer) OnDisconect(*websocket.Client, centrifuge.DisconnectEvent)
- func (*APIServer) OnHistory(*websocket.Client, centrifuge.HistoryEvent) (centrifuge.HistoryReply, error)
- func (*APIServer) OnMessage(*websocket.Client, centrifuge.MessageEvent)
- func (*APIServer) OnNotification(*centrifuge.Node, centrifuge.NotificationEvent)
- func (app *APIServer) OnPresence(_ *websocket.Client, e centrifuge.PresenceEvent) (centrifuge.PresenceReply, error)
- func (app *APIServer) OnPresenceStats(_ *websocket.Client, e centrifuge.PresenceStatsEvent) (centrifuge.PresenceStatsReply, error)
- func (*APIServer) OnPublish(*websocket.Client, centrifuge.PublishEvent) (centrifuge.PublishReply, error)
- func (apiServer *APIServer) OnRPC(c *websocket.Client, rpc centrifuge.RPCEvent) (centrifuge.RPCReply, error)
- func (*APIServer) OnRefresh(*websocket.Client, centrifuge.RefreshEvent) (centrifuge.RefreshReply, error)
- func (*APIServer) OnSubRefresh(*websocket.Client, centrifuge.SubRefreshEvent) (centrifuge.SubRefreshReply, error)
- func (app *APIServer) OnSubscribe(c *websocket.Client, e centrifuge.SubscribeEvent) (centrifuge.SubscribeReply, error)
- func (*APIServer) OnSurvey(*centrifuge.Node, centrifuge.SurveyEvent) centrifuge.SurveyReply
- func (*APIServer) OnUnsubscribe(*websocket.Client, centrifuge.UnsubscribeEvent)
- func (apiServer *APIServer) PublishEvent(channel string, event Event) (centrifuge.PublishResult, error)
- func (a *APIServer) Run() error
- func (apiServer *APIServer) Top10(_ *websocket.Client, _ []byte) (*RPCFindUserResponse, error)
- type ConfigReader
- type Database
- type Event
- type EventDeclineGameInvitation
- type EventGameEndedInDraw
- type EventGameEndedWithWinner
- type EventGameInvitation
- type EventGameInvitationExpired
- type EventGameStarted
- type EventMove
- type EventUserLeftGame
- type RPCAcceptGameInvitationRequest
- type RPCAcceptGameInvitationResponse
- type RPCBoardStateRequest
- type RPCBoardStateResponse
- type RPCCallForGameRequest
- type RPCCallForGameResponse
- type RPCDeclineGameInvitationRequest
- type RPCDeclineGameInvitationResponse
- type RPCFindUserRequest
- type RPCFindUserResponse
- type RPCGameHistoryRequest
- type RPCGameHistoryResponse
- type RPCGetUserRequest
- type RPCGetUserResponse
- type RPCIsPlayingRequest
- type RPCIsPlayingResponse
- type RPCLeaveGameRequest
- type RPCLeaveGameResponse
- type RPCMakeMoveRequest
- type RPCMakeMoveResponse
- type WebsocketSession
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) BoardState ¶
func (*APIServer) CallForGame ¶
func (*APIServer) DeclineGameInvitation ¶
func (*APIServer) GameHistory ¶
func (*APIServer) OnConnecting ¶
func (apiServer *APIServer) OnConnecting(_ *centrifuge.Node, e centrifuge.ConnectEvent) (websocket.Session, centrifuge.ConnectReply, error)
func (*APIServer) OnDisconect ¶
func (*APIServer) OnDisconect(*websocket.Client, centrifuge.DisconnectEvent)
func (*APIServer) OnHistory ¶
func (*APIServer) OnHistory(*websocket.Client, centrifuge.HistoryEvent) (centrifuge.HistoryReply, error)
func (*APIServer) OnMessage ¶
func (*APIServer) OnMessage(*websocket.Client, centrifuge.MessageEvent)
func (*APIServer) OnNotification ¶
func (*APIServer) OnNotification(*centrifuge.Node, centrifuge.NotificationEvent)
func (*APIServer) OnPresence ¶
func (app *APIServer) OnPresence(_ *websocket.Client, e centrifuge.PresenceEvent) (centrifuge.PresenceReply, error)
func (*APIServer) OnPresenceStats ¶
func (app *APIServer) OnPresenceStats(_ *websocket.Client, e centrifuge.PresenceStatsEvent) (centrifuge.PresenceStatsReply, error)
func (*APIServer) OnPublish ¶
func (*APIServer) OnPublish(*websocket.Client, centrifuge.PublishEvent) (centrifuge.PublishReply, error)
func (*APIServer) OnRPC ¶
func (apiServer *APIServer) OnRPC(c *websocket.Client, rpc centrifuge.RPCEvent) (centrifuge.RPCReply, error)
func (*APIServer) OnRefresh ¶
func (*APIServer) OnRefresh(*websocket.Client, centrifuge.RefreshEvent) (centrifuge.RefreshReply, error)
func (*APIServer) OnSubRefresh ¶
func (*APIServer) OnSubRefresh(*websocket.Client, centrifuge.SubRefreshEvent) (centrifuge.SubRefreshReply, error)
func (*APIServer) OnSubscribe ¶
func (app *APIServer) OnSubscribe(c *websocket.Client, e centrifuge.SubscribeEvent) (centrifuge.SubscribeReply, error)
func (*APIServer) OnSurvey ¶
func (*APIServer) OnSurvey(*centrifuge.Node, centrifuge.SurveyEvent) centrifuge.SurveyReply
func (*APIServer) OnUnsubscribe ¶
func (*APIServer) OnUnsubscribe(*websocket.Client, centrifuge.UnsubscribeEvent)
func (*APIServer) PublishEvent ¶
func (apiServer *APIServer) PublishEvent(channel string, event Event) (centrifuge.PublishResult, error)
type ConfigReader ¶
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 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 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 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 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
Source Files
¶
- apiserver.go
- config_reader_interface.go
- database_interface.go
- event.go
- middlewares.go
- oauth2.go
- rpc_accept_game_invitation.go
- rpc_call_for_game.go
- rpc_decline_game_invitation.go
- rpc_find_users.go
- rpc_game_history.go
- rpc_get_board_state.go
- rpc_get_user.go
- rpc_is_playing.go
- rpc_leave_game.go
- rpc_make_move.go
- rpc_top_10.go
- sign_in.go
- sign_up.go
- websocket_client_handler.go
- websocket_node_handler.go
Click to show internal directories.
Click to hide internal directories.