ws

package
v0.0.0-...-bf199b6 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EchoHandler

func EchoHandler(msg WebSocketMessage, ws *websocket.Conn, c echo.Context) error

func PipelineHandler

func PipelineHandler(msg WebSocketMessage, c *websocket.Conn, ctx echo.Context) error

Types

type MessageHandler

type MessageHandler func(WebSocketMessage, *websocket.Conn, echo.Context) error

type WS

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

WS is the representation of the WebSocket handler

func GetWS

func GetWS() *WS

GetWs retrieves the WebSocket singleton, making it if it hasn't been created yet.

func (*WS) Handle

func (w *WS) Handle(c echo.Context) error

Handle is the websocket handler for the echo server

func (*WS) RegisterHandle

func (w *WS) RegisterHandle(handler MessageHandler)

type WebSocketMessage

type WebSocketMessage struct {
	Message    string               `json:"message"`
	BinaryData []byte               `json:"binary"`
	Type       WebSocketMessageType `json:"type"`
}

WebSocketMessage is the shape of messages coming in from the Websocket

func (*WebSocketMessage) Render

func (m *WebSocketMessage) Render(c echo.Context) ([]byte, error)

Render will return either a []byte if WebSocketMessage Type is binary, otherwise it will return a string

type WebSocketMessageType

type WebSocketMessageType string

WebSocketMessageType can be "echo", "message", "binary"

const Binary WebSocketMessageType = "binary"
const Close WebSocketMessageType = "close"
const Echo WebSocketMessageType = "echo"
const Message WebSocketMessageType = "message"

Jump to

Keyboard shortcuts

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