Documentation ¶
Overview ¶
Package `server` implements the http/websocket front end for the ts2 simulator
Index ¶
- Constants
- func HttpdStart(addr, port string)
- func InitializeLogger(parentLogger log.Logger)
- func Run(s *simulation.Simulation, addr, port string)
- type ClientType
- type DataEvent
- type DataStatus
- type Hub
- type ManagerType
- type MessageType
- type ParamsListener
- type ParamsRegister
- type RawJSON
- type Request
- type RequestListener
- type RequestRegister
- type Response
- type ResponseNotification
- type ResponseStatus
- type StatusCode
Constants ¶
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 ¶
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 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 ¶
MarshalJSON returns m as the JSON encoding of r.
func (*RawJSON) UnmarshalJSON ¶
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 ¶
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.