service

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeWs

func ServeWs(server *Server, clientConfig *ClientConfig, logger *log.Entry) http.HandlerFunc

ServeWs registers a WS client

Types

type ClientConfig

type ClientConfig struct {
	WriteWait      time.Duration
	PongWait       time.Duration
	PingPeriod     time.Duration
	MaxMessageSize int64
}

ClientConfig contains configuration needed to communicate with the WS server

type MessagePayload

type MessagePayload struct {
	Message string `json:"message"`
	Type    string `json:"type"`
}

MessagePayload is the envelope for messages sent to and from the chat participants

type Server

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

Server is our hub for all WS clients

func NewServer

func NewServer(rabbitMQClient *rabbitmq.Client, botSymbol string, logger *log.Entry) *Server

NewServer instantiates a new server struct

func (*Server) ClientCount

func (server *Server) ClientCount() int

ClientCount returns the number of connected clients

func (*Server) ConsumeRMQ

func (server *Server) ConsumeRMQ()

ConsumeRMQ reads the RabbitMQ response queue and broadcasts it to clients

func (*Server) Run

func (server *Server) Run()

Run executes our websocket server to accpet its various requests

type WSClient

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

WSClient is the websocket client users will connect to

func NewWSClient

func NewWSClient(conn *websocket.Conn, server *Server, config *ClientConfig, logger *log.Entry, room string) *WSClient

NewWSClient instantiates a new websocket client

func (*WSClient) ExtractCommandAndArgs

func (client *WSClient) ExtractCommandAndArgs(message string) (string, string)

ExtractCommandAndArgs parses a bot command and any arguments it may have

func (*WSClient) IsValidBotCommand

func (client *WSClient) IsValidBotCommand(message string) bool

IsValidBotCommand verifies if a message should be treated as a bot command

Jump to

Keyboard shortcuts

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