handlers

package
v0.0.0-...-cbd5fac Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TextMessage denotes a text data message. The text message payload is
	// interpreted as UTF-8 encoded text data.
	TextMessage = 1

	// BinaryMessage denotes a binary data message.
	BinaryMessage = 2

	// CloseMessage denotes a close control message. The optional message
	// payload contains a numeric code and text. Use the FormatCloseMessage
	// function to format a close message payload.
	CloseMessage = 8

	// PingMessage denotes a ping control message. The optional message payload
	// is UTF-8 encoded text.
	PingMessage = 9

	// PongMessage denotes a pong control message. The optional message payload
	// is UTF-8 encoded text.
	PongMessage = 10
)

Control messages for websocket

Variables

This section is empty.

Functions

func ReadIncomingMessagesFromRabbit

func ReadIncomingMessagesFromRabbit()

ReadIncomingMessagesFromRabbit connects to a RabbitMQ server and starts a go routine that reads in new RabbitMQ messages and writes their contents to the correct WebSocket connections

Types

type CORSHeader

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

CORSHeader is a middleware handler that adds CORS headers to a response

func NewCORSHeader

func NewCORSHeader(handlerToWrap http.Handler) *CORSHeader

NewCORSHeader constructs a new ResponseHeader middleware handler

func (*CORSHeader) ServeHTTP

func (ch *CORSHeader) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles the request by adding CORS response headers If the request header method is OPTION return StatusOK so the actual client request can be sent

type Context

type Context struct {
	SessionIDKey string         `json:"sessionIDKey"`
	SessionStore sessions.Store `json:"sessionStore"`
	UserStore    users.Store    `json:"userStore"`
}

Context struct to contain the information about the context

func NewContext

func NewContext(sessionIDKey string, sessionStore sessions.Store, userStore users.Store) *Context

NewContext constructs a new Context struct, ensuring that the dependencies are valid values

func (*Context) SessionsHandler

func (hc *Context) SessionsHandler(w http.ResponseWriter, r *http.Request)

SessionsHandler handles requests for the "sessions" resource, and allows clients to begin a new session using an existing user's credentials.

func (*Context) SpecificSessionHandler

func (hc *Context) SpecificSessionHandler(w http.ResponseWriter, r *http.Request)

SpecificSessionHandler handles requests related to a specific authenticated session

func (*Context) SpecificUserHandler

func (hc *Context) SpecificUserHandler(w http.ResponseWriter, r *http.Request)

SpecificUserHandler handle requests for specific user

func (*Context) UsersHandler

func (hc *Context) UsersHandler(w http.ResponseWriter, r *http.Request)

UsersHandler creates new user accounts

func (*Context) WebSocketConnectionHandler

func (hc *Context) WebSocketConnectionHandler(w http.ResponseWriter, r *http.Request)

WebSocketConnectionHandler upgrades a client connection to a WebSocket connection, regardless of what method is used in the request

type Message

type Message struct {
	Type          string
	Channel       string `json:"channel"`
	ChannelID     string `json:"channelID"`
	UserMessage   string `json:"message"`
	UserMessageID string `json:"messageID"`
	UserIDs       []int64
}

Message represents a RabbitMQ message

type SessionState

type SessionState struct {
	Time time.Time   `json:"time"`
	User *users.User `json:"user"`
}

SessionState struct to contain the information about SessionState

func NewSessionState

func NewSessionState(time time.Time, user *users.User) *SessionState

NewSessionState constructs a new SessionState struct

type SocketStore

type SocketStore struct {
	Connections map[int64]*websocket.Conn
	// contains filtered or unexported fields
}

SocketStore represents a map of userIDs to WebSocket connections that is safe for concurrent use

func NewSocketStore

func NewSocketStore() *SocketStore

NewSocketStore constructs a new map of userIDs and WebSocket connections

func (*SocketStore) Delete

func (c *SocketStore) Delete(userID int64)

Delete removes the WebSocket connection for a given userID

func (*SocketStore) Get

func (c *SocketStore) Get(userID int64) *websocket.Conn

Get retrieves the WebSocket connection for a given userID

func (*SocketStore) Set

func (c *SocketStore) Set(userID int64, wsConn *websocket.Conn)

Set adds a new userID and WebSocket connection to the map

Jump to

Keyboard shortcuts

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