handlers

package
v0.0.0-...-a0c15bd Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Home

func Home(w http.ResponseWriter, r *http.Request)

Home renders the home page 1. Somebody connects to the webpage: func Home <- display the webpage

func ListenForWs

func ListenForWs(conn *WebSocketConnection)

Goroutine to listen for messages from the websocket 3. When we connect to WS:

  1. go ListenForWs(&conn) <- is called
  2. go ListenForWs(&conn) <- is a goroutine on a infite loop
  3. wsChan <- payload <- everything sent on the payload is pass to wsChan

func ListenToWsChannel

func ListenToWsChannel()
  1. Everything on the the payload is store on the variable e func ListenToWsChannel() <- everything on the the payload is store on the variable e
  2. Here is where we process the payload, the logic, where we stract the username or the message.

func WsEndpoint

func WsEndpoint(w http.ResponseWriter, r *http.Request)

WsEndpoint upgrades connection to websocket 2. func WsEndpoint is called to connect the WS

Types

type WebSocketConnection

type WebSocketConnection struct {
	*websocket.Conn
}

type WsJsonResponse

type WsJsonResponse struct {
	Action         string   `json:"action"`
	Message        string   `json:"message"`
	MessageType    string   `json:"message_type"`
	ConnectedUsers []string `json:"connected_users"`
}

WsJsonResponse defines the response sent back from websocket

type WsPayload

type WsPayload struct {
	Action   string              `json:"action"`
	Username string              `json:"username"`
	Message  string              `json:"message"`
	Conn     WebSocketConnection `json:"-"`
}

WsPayload defines the websocket request from the client

Jump to

Keyboard shortcuts

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