server

package
v0.0.0-...-3517908 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIDefinition

func APIDefinition(w http.ResponseWriter, r *http.Request)

APIDefinition serves the swagger description for this service

func Logger

func Logger(inner http.Handler, name string) http.Handler

Logger logs http requests with handle times.

func NewRouter

func NewRouter(api *API) *mux.Router

NewRouter creates a router with routes for the MMOCG API

Types

type API

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

API uses a store to respond to API requests

func NewAPI

func NewAPI(store Store) API

NewAPI creates an API handler using the given store

func (*API) Click

func (api *API) Click(w http.ResponseWriter, r *http.Request)

Click reports clicks for the given team

func (*API) GetLeaderboard

func (api *API) GetLeaderboard(w http.ResponseWriter, r *http.Request)

GetLeaderboard returns the highest scoring teams

func (*API) GetTeamByID

func (api *API) GetTeamByID(w http.ResponseWriter, r *http.Request)

GetTeamByID returns a single team if found by ID

func (*API) UpdateTeam

func (api *API) UpdateTeam(w http.ResponseWriter, r *http.Request)

UpdateTeam creates or updates a team using the form data from the request

type Leaderboard

type Leaderboard []Team

Leaderboard is a collection of the highest scoring teams

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

Route maps a path pattern to a handler function.

type Routes

type Routes []Route

Routes is a set of routes.

type Store

type Store interface {
	// error must mean the team ID is taken
	CreateTeam(teamID string) (Team, error)
	FindByID(teamID string) (Team, error)
	GetLeaderboard() (Leaderboard, error)
	RecordClicks(teamID string, count int64) (Team, error)
	Close()
}

Store stores scores and teams

type Team

type Team struct {
	ID     string `json:"id,omitempty"`
	Clicks int64  `json:"clicks,omitempty"`
}

Team is a collection of players clicking things

Jump to

Keyboard shortcuts

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