Documentation
¶
Index ¶
- Constants
- Variables
- func AddGuestProvider(s *auth.Service, issuer string, logger logger.L, name string, ...)
- func ErrBadRequest(err error) render.Renderer
- func ErrConflict(err error) render.Renderer
- func ErrInternalServerError(err error) render.Renderer
- func Start(config config.Config) error
- type DBClient
- type DBConnection
- type ErrResponse
- type GameRunner
- type GuestHandler
- type HashChecker
- type HashCheckerFunc
- type TurnGenerationCheckResult
Constants ¶
const (
// MaxHTTPBodySize defines max http body size
MaxHTTPBodySize = 1024 * 1024
)
Variables ¶
var ErrForbidden = &ErrResponse{HTTPStatusCode: http.StatusForbidden, StatusText: "Forbidden."}
var ErrNotFound = &ErrResponse{HTTPStatusCode: http.StatusNotFound, StatusText: "Resource not found."}
Functions ¶
func AddGuestProvider ¶
func AddGuestProvider(s *auth.Service, issuer string, logger logger.L, name string, hashChecker HashChecker)
AddGuestProvider adds provider with guest invite link checks against a data store it doesn't do any handshake and uses provided hashChecker to verify a user exists with a hash from the request
func ErrBadRequest ¶
error for bad requests from the caller. Maybe they malformed a url or sent a payload with invalid data
func ErrConflict ¶
func ErrInternalServerError ¶
error for unexpected server issues like db connections this could be because of a bug in our code (like we failed to validate a unique constraint) but most likely it's some server specific thing we want to view in the logs
Types ¶
type DBConnection ¶
type ErrResponse ¶
type ErrResponse struct { Err error `json:"-"` // low-level runtime error HTTPStatusCode int `json:"-"` // http response status code StatusText string `json:"status"` // user-level status message ErrorText string `json:"error,omitempty"` // application-level error message, for debugging }
ErrResponse renderer type for handling all sorts of errors.
In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.
func (*ErrResponse) Render ¶
func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error
type GameRunner ¶
type GameRunner interface { HostGame(hostID int64, settings *cs.GameSettings) (*cs.FullGame, error) JoinGame(gameID int64, userID int64, name string, race cs.Race) error LeaveGame(gameID, userID int64) error KickPlayer(gameID int64, playerNum int) error AddOpenPlayerSlot(game *cs.GameWithPlayers) (*cs.Player, error) AddGuestPlayer(game *cs.GameWithPlayers) (*cs.Player, error) AddAIPlayer(game *cs.GameWithPlayers) (*cs.Player, error) DeletePlayerSlot(gameID int64, playerNum int) error StartGame(game *cs.Game) error LoadPlayerGame(gameID int64, userID int64) (*cs.GameWithPlayers, *cs.FullPlayer, error) SubmitTurn(gameID int64, userID int64) error CheckAndGenerateTurn(gameID int64) (TurnGenerationCheckResult, error) GenerateTurn(gameID int64) (TurnGenerationCheckResult, error) }
The GameRunner handles hosting games, updating players of games before they are started, loading a full Player game from the database, and generating new turns.
func NewGameRunner ¶
func NewGameRunner(dbConn DBConnection, config config.Config) GameRunner
type GuestHandler ¶
type GuestHandler struct { logger.L HashChecker HashChecker ProviderName string TokenService provider.TokenService Issuer string }
GuestHandler implements non-oauth2 provider authorizing user in traditional way with storage with users and hashes
func (GuestHandler) AuthHandler ¶
func (p GuestHandler) AuthHandler(http.ResponseWriter, *http.Request)
AuthHandler doesn't do anything for guest login as it has no callbacks
func (GuestHandler) LoginHandler ¶
func (p GuestHandler) LoginHandler(w http.ResponseWriter, r *http.Request)
LoginHandler checks "hash" against data store and makes jwt if all passed.
POST /something?sess[0|1] Accepts application/x-www-form-urlencoded or application/json encoded requests.
application/x-www-form-urlencoded body example: user=name&passwd=xyz&aud=bar
application/json body example:
{ "hash": "123xyz", "aud": "bar", }
func (GuestHandler) LogoutHandler ¶
func (p GuestHandler) LogoutHandler(w http.ResponseWriter, _ *http.Request)
LogoutHandler - GET /logout
type HashChecker ¶
type HashChecker interface {
Check(hash string) (username string, attributes map[string]interface{}, err error)
}
HashChecker defines interface to check credentials
type HashCheckerFunc ¶
type HashCheckerFunc func(hash string) (username string, attributes map[string]interface{}, err error)
HashCheckerFunc type is an adapter to allow the use of ordinary functions as CredsChecker.
type TurnGenerationCheckResult ¶
type TurnGenerationCheckResult uint
const ( TurnNotGenerated TurnGenerationCheckResult = iota TurnGenerated )