api

package
v0.0.0-...-b8f7dfc Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEndpointMethodNotAllowed - Method supplied was not allowed.
	ErrEndpointMethodNotAllowed = errors.New("method not allowed")
	// ErrEndpointForbidden - API endpoint forbidden.
	ErrEndpointForbidden = errors.New("forbidden")
	// ErrInvalidPageNumber - Invalid page number.
	ErrInvalidPageNumber = errors.New("invalid page number")
	// ErrInternalServerError - Internal server error.
	ErrInternalServerError = errors.New("internal server error")
	// ErrInvalidPlayerID - Invalid player id.
	ErrInvalidPlayerID = errors.New("invalid player id")
	// ErrPlayerNotFound - Player not found.
	ErrPlayerNotFound = errors.New("player not found")
	// ErrInvalidPlayerDetails - Invalid player details.
	ErrInvalidPlayerDetails = errors.New("invalid player details")
	// ErrInvalidTeamID - Invalid team id.
	ErrInvalidTeamID = errors.New("invalid team id")
	// ErrTeamNotFound - Team not found.
	ErrTeamNotFound = errors.New("team not found")
	// ErrInvalidGameType - Game type invalid.
	ErrInvalidGameType = errors.New("invalid game type")
	// ErrInvalidGameVsMode - Game mode invalid.
	ErrInvalidGameVsMode = errors.New("invalid game mode")
	// ErrInvalidGameDirection - Game direction invalid.
	ErrInvalidGameDirection = errors.New("invalid game direction")
	// ErrUnableToBroadcastUpdate - Unable to broadcast update.
	ErrUnableToBroadcastUpdate = errors.New("unable to broadcast update")
	// ErrTournamentNotFound - Tournament not found.
	ErrTournamentNotFound = errors.New("tournament not found")
	// ErrInvalidTournamentID - Invalid tournament id.
	ErrInvalidTournamentID = errors.New("invalid tournament id")
	// ErrInvalidTournamentDetails - Invalid tournament details.
	ErrInvalidTournamentDetails = errors.New("invalid tournament details")
	// ErrInvalidTableNumber - Invalid table number.
	ErrInvalidTableNumber = errors.New("invalid table number")
	// ErrRemoveOnlyTable - Cannot remove only table.
	ErrRemoveOnlyTable = errors.New("cannot remove only table")
)
View Source
var VersionLatest = "latest"

VersionLatest is the latest version for the API. We should only be using this for development.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host      string   `json:"host"`
	Port      string   `json:"port"`
	PublicDir string   `json:"public_dir"`
	Version   *Version `json:"version"`
}

Config is the configuration for the API package.

type CountResp

type CountResp struct {
	Count int64 `json:"count"`
}

CountResp is a count of entities for the endpoint.

type ErrorResp

type ErrorResp struct {
	Err string `json:"error"`
}

ErrorResp is an error response.

type GameFargoHotHandicapPatchBody

type GameFargoHotHandicapPatchBody struct {
	UseFargoHotHandicap bool `json:"useFargoHotHandicap"`
}

GameFargoHotHandicapPatchBody is the incoming body on a patch request for updating the fargo hot handicap.

type GameFargoHotHandicapPatchResp

type GameFargoHotHandicapPatchResp struct {
	UseFargoHotHandicap bool `json:"useFargoHotHandicap"`
}

GameFargoHotHandicapPatchResp is the response containing the new fargo hot handicap setting.

type GamePlayersDeleteBody

type GamePlayersDeleteBody struct {
	PlayerNum int `json:"playerNum"`
}

GamePlayersDeleteBody is the incoming body on a delete request for unsetting the specified player num.

type GamePlayersFlagPatchBody

type GamePlayersFlagPatchBody struct {
	PlayerNum int `json:"playerNum"`
	FlagID    int `json:"flagID"`
}

GamePlayersFlagPatchBody is the incoming body on a patch request for updating the player num to a specified flag id.

type GamePlayersNamePatchBody

type GamePlayersNamePatchBody struct {
	PlayerNum int    `json:"playerNum"`
	Name      string `json:"name"`
}

GamePlayersNamePatchBody is the incoming body on a patch request for updating the player name for the specified player num.

type GamePlayersPatchBody

type GamePlayersPatchBody struct {
	PlayerNum int `json:"playerNum"`
	PlayerID  int `json:"playerID"`
}

GamePlayersPatchBody is the incoming body on a patch request for updating the player num to a specified player id.

type GameRaceToPatchBody

type GameRaceToPatchBody struct {
	Direction string `json:"direction"`
}

GameRaceToPatchBody is the incoming body on a patch request for updating the game race to.

type GameRaceToResp

type GameRaceToResp struct {
	RaceTo              int  `json:"raceTo"`
	UseFargoHotHandicap bool `json:"useFargoHotHandicap"`
}

GameRaceToResp is a reponse containing the game race to.

type GameScorePatchBody

type GameScorePatchBody struct {
	PlayerNum int    `json:"playerNum"`
	Direction string `json:"direction"`
}

GameScorePatchBody is the incoming body on a patch request for updating the game score for the specified player.

type GameScoreResp

type GameScoreResp struct {
	ScoreOne int `json:"scoreOne"`
	ScoreTwo int `json:"scoreTwo"`
}

GameScoreResp is a reponse containing the game score.

type GameTeamsPatchBody

type GameTeamsPatchBody struct {
	TeamNum int `json:"teamNum"`
	TeamID  int `json:"teamID"`
}

GameTeamsPatchBody is the incoming body on a patch request for updating the team for the specified team number.

type GameTypePatchBody

type GameTypePatchBody struct {
	Type models.GameType `json:"type"`
}

GameTypePatchBody is the incoming body on a patch request for updating the game type.

type GameTypeResp

type GameTypeResp struct {
	Type models.GameType `json:"type"`
}

GameTypeResp is a reponse containing the game type.

type GameVsModePatchBody

type GameVsModePatchBody struct {
	VsMode models.GameVsMode `json:"vsMode"`
}

GameVsModePatchBody is the incoming body on a patch request for updating the game vs mode.

type GameVsModeResp

type GameVsModeResp struct {
	VsMode models.GameVsMode `json:"vsMode"`
}

GameVsModeResp is a reponse containing the game type.

type OverlayToggleFargoResp

type OverlayToggleFargoResp struct {
	ShowFargo bool `json:"showFargo"`
}

OverlayToggleFargoResp is the response from toggling fargo ratings on the overlay.

type OverlayToggleFlagsResp

type OverlayToggleFlagsResp struct {
	ShowFlags bool `json:"showFlags"`
}

OverlayToggleFlagsResp is the response from toggling flags on the overlay.

type OverlayToggleResp

type OverlayToggleResp struct {
	Hidden bool `json:"hidden"`
}

OverlayToggleResp is the response from toggling the overlay.

type OverlayToggleScoreResp

type OverlayToggleScoreResp struct {
	ShowScore bool `json:"showScore"`
}

OverlayToggleScoreResp is the response from toggling the player scores on the overlay.

type PlayersPatchBody

type PlayersPatchBody struct {
	Name              string `json:"name"`
	FlagID            uint   `json:"flag_id"`
	FargoObservableID uint   `json:"fargo_observable_id"`
	FargoID           uint   `json:"fargo_id"`
	FargoRating       uint   `json:"fargo_rating"`
}

PlayersPatchBody is an incoming body on a PATCH request for updating a player.

type PlayersPostBody

type PlayersPostBody struct {
	Name              string `json:"name"`
	FlagID            uint   `json:"flag_id"`
	FargoObservableID uint   `json:"fargo_observable_id"`
	FargoID           uint   `json:"fargo_id"`
	FargoRating       uint   `json:"fargo_rating"`
}

PlayersPostBody is an incoming body on a POST request for creating a player.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an api server.

func NewServer

func NewServer(config *Config, db *gorm.DB, overlay *overlay.Overlay, telestrator *telestrator.Telestrator, tables map[int]*state.State, challonge *challonge.Challonge) *Server

NewServer returns a new api server.

func (*Server) AddRoute

func (server *Server) AddRoute(path string, handler http.Handler)

AddRoute adds a route and handler to the router.

func (*Server) AddRouteToAllVersions

func (server *Server) AddRouteToAllVersions(path string, handler http.Handler)

AddRouteToAllVersions adds the route to all versions of the api.

func (*Server) AddRouteToVersion

func (server *Server) AddRouteToVersion(version string, path string, handler http.Handler)

AddRouteToVersion adds a route to a versioned subrouter.

func (*Server) AddVersion

func (server *Server) AddVersion(version string)

AddVersion adds a new sub router with version prefix

func (*Server) HandleOptions

func (server *Server) HandleOptions(w http.ResponseWriter, r *http.Request)

HandleOptions returns a 200 status code for preflight checks.

func (*Server) Handler

func (server *Server) Handler() http.Handler

Handler handles incoming api routes.

func (*Server) Init

func (server *Server) Init()

Init initializes the api server.

func (*Server) InitRoutes

func (server *Server) InitRoutes()

InitRoutes adds all routes to the api.

func (*Server) Run

func (server *Server) Run() error

Run starts the api server.

func (*Server) SetupResponse

func (server *Server) SetupResponse(w http.ResponseWriter, r *http.Request)

SetupResponse adds CORS headers to an API response.

type TournamentLoadBody

type TournamentLoadBody struct {
	ID       int                        `json:"id"`
	Settings TournamentLoadBodySettings `json:"settings"`
}

type TournamentLoadBodySettings

type TournamentLoadBodySettings struct {
	MaxTables     int             `json:"max_tables"`
	GameType      models.GameType `json:"game_type"`
	ShowOverlay   bool            `json:"show_overlay"`
	ShowFlags     bool            `json:"show_flags"`
	ShowFargo     bool            `json:"show_fargo"`
	ShowScore     bool            `json:"show_score"`
	IsHandicapped bool            `json:"is_handicapped"`
	ASideRaceTo   int             `json:"a_side_race_to"`
	BSideRaceTo   int             `json:"b_side_race_to"`
}

type Version

type Version struct {
	Current  string `json:"current"`
	Previous string `json:"previous"`
}

Version is loaded from the config and used to allow for one version back.

Jump to

Keyboard shortcuts

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