web

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActiveGamesHandler activeGamesHandler
View Source
var ApiNotFoundHandler apiNotFoundHandler
View Source
var AuthChallengeHandler authChallengeHandler
View Source
var AuthResponseHandler authResponseHandler
View Source
var (
	// ErrParser is thrown when a request object is of the wrong type
	ErrParser error = errParse{}
)
View Source
var GetGameHandler getGameHandler
View Source
var HomeHandler homeHandler
View Source
var MoveHandler moveHandler
View Source
var NewGameHandler newGameHandler
View Source
var NewSessionHandler newSessionHandler
View Source
var NextMoveHandler nextMoveHandler
View Source
var WhoAmIHandler whoAmIHandler

Functions

This section is empty.

Types

type ActiveGamesResponse

type ActiveGamesResponse struct {
	GameIDs []string `json:"gameid"`
}

The ActiveGamesResponse wraps a ActiveGamesHandler API response

func (ActiveGamesResponse) FlaggedAsResponse

func (ActiveGamesResponse) FlaggedAsResponse()

type ApiNotFoundResponse

type ApiNotFoundResponse struct {
}

The ApiNotFoundResponse wraps a ApiNotFoundHandler API response

func (ApiNotFoundResponse) FlaggedAsResponse

func (ApiNotFoundResponse) FlaggedAsResponse()

type AuthChallengeRequest

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

func (AuthChallengeRequest) FlaggedAsRequest

func (AuthChallengeRequest) FlaggedAsRequest()

type AuthChallengeResponse

type AuthChallengeResponse struct {
	Nonce string `json:"nonce"`
}

The AuthChallengeResponse wraps a AuthChallengeHandler API response

func (AuthChallengeResponse) FlaggedAsResponse

func (AuthChallengeResponse) FlaggedAsResponse()

type AuthResponseRequest

type AuthResponseRequest struct {
	Username string `json:"username"`
	Nonce    string `json:"nonce"`
	Response string `json:"response"`
}

func (AuthResponseRequest) FlaggedAsRequest

func (AuthResponseRequest) FlaggedAsRequest()

type AuthResponseResponse

type AuthResponseResponse struct {
}

The AuthResponseResponse wraps a AuthResponseHandler API response

func (AuthResponseResponse) FlaggedAsResponse

func (AuthResponseResponse) FlaggedAsResponse()

type GetGameResponse

type GetGameResponse struct {
	Game *game.Game
}

The GetGameResponse wraps a GetGameHandler API response

func (GetGameResponse) FlaggedAsResponse

func (GetGameResponse) FlaggedAsResponse()

type Handler

type Handler interface {
	// DecodeRequest turns a HTTP request into a domain-specific request type
	DecodeRequest(*http.Request) (Request, error)

	// A RequestHandler is a monadic definition of a request handler. The inputs
	// are the current state of the world, and a handler-specific request type,
	// and the output is the new state of the world (which may or may not be the
	// same), a handler-specific response type, and/or an error.
	HandleRequest(Provider, Request) (Response, error)
}

A Handler handles requests

type MoveRequest

type MoveRequest struct {
	From string `json:"from"`
	To   string `json:"to"`
}

func (MoveRequest) FlaggedAsRequest

func (MoveRequest) FlaggedAsRequest()

type MoveResponse

type MoveResponse struct {
}

The MoveResponse wraps a MoveHandler API response

func (MoveResponse) FlaggedAsResponse

func (MoveResponse) FlaggedAsResponse()

type NewGameRequest

type NewGameRequest struct {
	RuleSet     string   `json:"ruleset"`
	PlayerNames []string `json:"players"`
}

func (NewGameRequest) FlaggedAsRequest

func (NewGameRequest) FlaggedAsRequest()

type NewGameResponse

type NewGameResponse struct {
	GameID string `json:"gameid"`
}

The NewGameResponse wraps a NewGameHandler API response

func (NewGameResponse) FlaggedAsResponse

func (NewGameResponse) FlaggedAsResponse()

type NewSessionResponse

type NewSessionResponse struct {
	SessionID string `json:"session_id"`
}

The NewSessionResponse wraps a NewSessionHandler API response

func (NewSessionResponse) FlaggedAsResponse

func (NewSessionResponse) FlaggedAsResponse()

type NextMoveResponse

type NextMoveResponse struct {
	Move *chesseract.Move `json:"move,omitempty"`
}

The NextMoveResponse wraps a NextMoveHandler API response

func (NextMoveResponse) FlaggedAsResponse

func (NextMoveResponse) FlaggedAsResponse()

type Provider

type Provider interface {
	// NewSession generates a new empty session, and returns a string
	// representation of its ID, to be communicated to the client.
	NewSession() (string, error)

	// Player returns the player associated with this session
	Player() (game.Player, error)

	// SetPlayer assigns this player to this session
	SetPlayer(game.Player) error

	// LookupPlayer finds the profile in the database, if it exists
	LookupPlayer(string) (game.Player, bool, error)

	// NewNonce generates a new auth challenge for this player
	NewNonce(string) (string, error)

	// ValidateNonce checks if a nonce is valid for this player
	ValidateNonce(playerName string, nonce string) (bool, error)

	// ActiveGames returns the list of active game ID's in which the player is involved
	ActiveGames() ([]string, error)

	// GetGame retrieves a game by its ID
	GetGame(gameid string) (*game.Game, error)

	// NewGame creates a new game with the specified players, and returns its game ID
	NewGame(ruleset string, playerNames []string) (string, error)

	// Game returns the game object of the currently active game session, if applicable
	Game() (*game.Game, error)

	// SubmitMove appends a move to the currently active game
	SubmitMove(chesseract.Move) error
}

The Provider is the Handlers' interface to the data backend. It is assumed that the Provider has performed all necessary context wrangling and cookie consuming

type Request

type Request interface {
	FlaggedAsRequest()
}

A Request flags any request type

type Response

type Response interface {
	FlaggedAsResponse()
}

A Response flags any response type

type WhoAmIResponse

type WhoAmIResponse struct {
	Profile game.Player `json:"profile"`
}

The WhoAmIResponse wraps a WhoAmIHandler API response

func (WhoAmIResponse) FlaggedAsResponse

func (WhoAmIResponse) FlaggedAsResponse()

Jump to

Keyboard shortcuts

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