server

package
v0.0.0-...-f2ba6e3 Latest Latest
Warning

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

Go to latest
Published: May 12, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Hub  *Hub
	Conn *websocket.Conn
	Send chan []byte
}

Client represents an individual websocket connection to the server

func (*Client) ReadPump

func (c *Client) ReadPump()

ReadPump listens for chat messages from a single client When it recieves a message, it then broadcasts the message to all other chat clients

func (*Client) WritePump

func (c *Client) WritePump()

WritePump sends broadcasted chat messages to the client connection

type Hub

type Hub struct {
	Clients    map[*Client]bool
	Broadcast  chan []byte
	Register   chan *Client
	Unregister chan *Client
}

Hub maintains the websocket connection state. Clients communicate with each other via the hub channels

func NewHub

func NewHub() *Hub

NewHub creates a new Hub

func (*Hub) Run

func (h *Hub) Run()

Run start the hub listening to channel events

type Message

type Message struct {
	Event string          `json:"event"`
	Data  json.RawMessage `json:"data"`
}

Message is the generic JSON message data structure sent between client and server

type Server

type Server struct {
	Router *chi.Mux
	Hub    *Hub
	DB     *sqlx.DB
}

Server encapsulates the server's outside connections

func (*Server) Middlewares

func (s *Server) Middlewares()

Middlewares adds middlwares to our HTTP handlers

func (*Server) Routes

func (s *Server) Routes()

Routes handles all application routing

Jump to

Keyboard shortcuts

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