server

package
v0.0.0-...-62d5368 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxHTTPBodySize defines max http body size
	MaxHTTPBodySize = 1024 * 1024
)

Variables

View Source
var ErrForbidden = &ErrResponse{HTTPStatusCode: http.StatusForbidden, StatusText: "Forbidden."}
View Source
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

func ErrBadRequest(err error) render.Renderer

error for bad requests from the caller. Maybe they malformed a url or sent a payload with invalid data

func ErrConflict

func ErrConflict(err error) render.Renderer

func ErrInternalServerError

func ErrInternalServerError(err error) render.Renderer

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

func GetAssets

func GetAssets() embed.FS

func SetAssets

func SetAssets(value embed.FS)

func Start

func Start(config config.Config) error

Start the webserver, expose all the routes, inject all the middleware, etc.

Types

type DBClient

type DBClient db.Client

type DBConnection

type DBConnection db.DBConn

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

func (GuestHandler) Name

func (p GuestHandler) Name() string

Name of the handler

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.

func (HashCheckerFunc) Check

func (f HashCheckerFunc) Check(hash string) (username string, attributes map[string]interface{}, err error)

Check calls f(user,passwd)

type TurnGenerationCheckResult

type TurnGenerationCheckResult uint
const (
	TurnNotGenerated TurnGenerationCheckResult = iota
	TurnGenerated
)

Jump to

Keyboard shortcuts

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