server

package
v0.0.0-...-c857007 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package server runs the http server with allows users to open websockets to play the game

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// AppName is the display name of the application
	AppName string
	// Port is the port number to run the server on
	Port string
	// Log is used to log errors and other information
	Log *log.Logger
	// Tokenizer is used to generate and parse session tokens
	Tokenizer Tokenizer
	// UserDao is used to track different users
	UserDao *db.UserDao
	// LobbyCfg is used to create a game lobby
	LobbyCfg lobby.Config
	// StopDur is the maximum duration the server should take to shutdown gracefully
	StopDur time.Duration
	// CachenSec is the number of seconds some files are cached
	CacheSec int
}

Config contains fields which describe the server

func (Config) NewServer

func (cfg Config) NewServer() (*Server, error)

NewServer creates a Server from the Config

type Server

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

Server runs the site

func (Server) Run

func (s Server) Run(ctx context.Context)

Run runs the server until it receives a shutdown signal.

func (Server) Stop

func (s Server) Stop(ctx context.Context) error

Stop asks the server to shutdown and waits for the shutdown to complete. An error is returned if the server if the context times out.

type Tokenizer

type Tokenizer interface {
	Create(u db.User) (string, error)
	ReadUsername(tokenString string) (string, error)
}

Tokenizer creates and reads tokens from http traffic.

type TokenizerConfig

type TokenizerConfig struct {
	// Rand is used to generate token keys
	Rand *rand.Rand
	// TimeFunc is a function which should supply the current time since the unix epoch.
	// Used to set the the length of time the token is valid
	TimeFunc func() int64
	// ValidSec is the length of time the token is valid from the issuing time, in seconds
	ValidSec int64
}

TokenizerConfig contains fields which describe a Tokenizer

func (TokenizerConfig) NewTokenizer

func (cfg TokenizerConfig) NewTokenizer() (Tokenizer, error)

NewTokenizer creates a Tokenizer that users the random number generator to generate tokens

Jump to

Keyboard shortcuts

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