websocket

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: GPL-3.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	MsgTypeError = "error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
}

type WebsocketHandler

type WebsocketHandler = func(msg WebsocketMessage, conn *websocket.Conn)

type WebsocketMessage

type WebsocketMessage struct {
	Type    string          `json:"type"`
	ID      string          `json:"id"`
	Payload json.RawMessage `json:"payload"`
	Error   *ErrorResponse  `json:"error,omitempty"`
}

type WebsocketServer

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

func NewWebsocketServer

func NewWebsocketServer(r chi.Router, logger *slog.Logger) *WebsocketServer

func (*WebsocketServer) RegisterHandler

func (s *WebsocketServer) RegisterHandler(msgType string, handler WebsocketHandler)

func (*WebsocketServer) SendErrorResponse

func (s *WebsocketServer) SendErrorResponse(conn *websocket.Conn, msgID string, msgType string, errorMessage string)

func (*WebsocketServer) SendGenericError

func (s *WebsocketServer) SendGenericError(conn *websocket.Conn, msgID string, errorMsg string)

func (*WebsocketServer) SendResponse

func (s *WebsocketServer) SendResponse(conn *websocket.Conn, msgID string, msgType string, payload interface{})

func (*WebsocketServer) Shutdown

func (s *WebsocketServer) Shutdown(timeout time.Duration) error

Shutdown gracefully shuts down the websocket server

Jump to

Keyboard shortcuts

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