server

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: GPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package `server` implements the http/websocket front end for the ts2 simulator

Index

Constants

View Source
const (
	DefaultAddr       string = "0.0.0.0"
	DefaultPort       string = "22222"
	MaxHubStartupTime        = 3 * time.Second
)

Variables

This section is empty.

Functions

func HttpdStart

func HttpdStart(addr, port string)

HttpdStart starts the server which serves on the following routes:

/ - Serves a HTTP home page with the server status and information about the loaded sim.
    It also includes a JavaScript WebSocket client to communicate and manage the server.

/ws - WebSocket endpoint for all TS2 clients and managers.

func InitializeLogger

func InitializeLogger(parentLogger log.Logger)

InitializeLogger creates the logger for the server module

func Run

func Run(s *simulation.Simulation, addr, port string)

Run starts a http web server and websocket hub for the given simulation, on the given address and port.

Types

type ClientType

type ClientType string
const (
	Client ClientType = "client"
)

type DataEvent

type DataEvent struct {
	Name   simulation.EventName `json:"name"`
	Object interface{}          `json:"object"`
}

DataEvent is the Data part of a ResponseNotification message

type DataStatus

type DataStatus struct {
	Status  StatusCode `json:"status"`
	Message string     `json:"message"`
}

DataStatus is the Data part of a ResponseStatus message

type Hub

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

The Hub makes the interface between the Simulation and the websocket clients

type ManagerType

type ManagerType string

type MessageType

type MessageType string

A MessageType defines the type of a JSON message on websocket

const (
	TypeResponse     MessageType = "response"
	TypeNotification MessageType = "notification"
)

type ParamsListener

type ParamsListener struct {
	Event simulation.EventName `json:"event"`
	IDs   []string             `json:"ids"`
}

ParamsListener is the struct of the Request Params for a RequestListener

type ParamsRegister

type ParamsRegister struct {
	ClientType    ClientType  `json:"type"`
	ClientSubType ManagerType `json:"subType"`
	Token         string      `json:"token"`
}

ParamsRegister is the struct of the Request Params for a RequestRegister

type RawJSON

type RawJSON json.RawMessage

RawJSON is a json.RawMessage (i.e. []byte) that prints itself as a string to be human readable in logs

func (RawJSON) MarshalJSON

func (r RawJSON) MarshalJSON() ([]byte, error)

MarshalJSON returns m as the JSON encoding of r.

func (RawJSON) String

func (r RawJSON) String() string

String function for the RawJSON type

func (*RawJSON) UnmarshalJSON

func (r *RawJSON) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *r to a copy of data.

type Request

type Request struct {
	ID     int     `json:"id"`
	Object string  `json:"object"`
	Action string  `json:"action"`
	Params RawJSON `json:"params"`
}

Request is a generic request made by a websocket client.

It is used before dispatching and unmarshaling into a specific request type.

type RequestListener

type RequestListener struct {
	ID     int            `json:"id"`
	Object string         `json:"object"`
	Action string         `json:"action"`
	Params ParamsListener `json:"params"`
}

RequestListener is a request made by a websocket client to add or remove a listener.

type RequestRegister

type RequestRegister struct {
	ID     int            `json:"id"`
	Object string         `json:"object"`
	Action string         `json:"action"`
	Params ParamsRegister `json:"params"`
}

RequestRegister is a request made by a websocket client to log onto the server.

type Response

type Response struct {
	ID      int         `json:"id"`
	MsgType MessageType `json:"msgType"`
	Data    RawJSON     `json:"data"`
}

Response is a status message sent to a websocket client

func NewResponse

func NewResponse(id int, data RawJSON) *Response

NewResponse returns a Response with the given data

type ResponseNotification

type ResponseNotification struct {
	MsgType MessageType `json:"msgType"`
	Data    DataEvent   `json:"data"`
}

ResponseNotification is a message sent by the server to the clients when an event is triggered in the simulation

func NewNotificationResponse

func NewNotificationResponse(e *simulation.Event) *ResponseNotification

NewNotificationResponse returns a new ResponseNotification object from the given Event

type ResponseStatus

type ResponseStatus struct {
	ID      int         `json:"id"`
	MsgType MessageType `json:"msgType"`
	Data    DataStatus  `json:"data"`
}

ResponseStatus is a status message sent to a websocket client

func NewErrorResponse

func NewErrorResponse(id int, e error) *ResponseStatus

NewErrorResponse returns a ResponseStatus object corresponding to the given error.

func NewOkResponse

func NewOkResponse(id int, msg string) *ResponseStatus

NewOkResponse returns a new ResponseStatus object with OK status and empty message.

type StatusCode

type StatusCode string
const (
	Ok   StatusCode = "OK"
	Fail StatusCode = "FAIL"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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