ws

package
v1.6.7-0...-b28dd99 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UpstreamHandler

func UpstreamHandler(addr string) http.HandlerFunc

UpstreamHandler proxies HTTP requests to running WebSocket server or application.

Types

type App

type App struct {
	Clients []*Client
	// contains filtered or unexported fields
}

App contains logic of client interfaction.

func NewApp

func NewApp(logger *zap.SugaredLogger) *App

NewApp inits new app instance and returns it.

func (*App) Broadcast

func (a *App) Broadcast(sub string, data map[string]interface{})

Broadcast sends socket event to all subscribers.

func (*App) InitClient

func (a *App) InitClient(client *Client) error

InitClient initializes reading client input messages.

func (*App) Register

func (a *App) Register(conn net.Conn, claims auth.UserClaims) *Client

Register registers new connection as app Client.

func (*App) Remove

func (a *App) Remove(client *Client)

Remove removes client from app.

type Client

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

Client defines websocket connection. It contains logic of receiving and sending messages. That is, there are no active reader or writer. Some other layer of the application should call Receive() to read user's incoming message.

func (*Client) Receive

func (c *Client) Receive() (*Message, error)

Receive reads next message from user's underlying connection. It blocks until full message received.

func (*Client) Send

func (c *Client) Send(mtype string, data Object) error

Send sends message to user's underlying connection.

type Message

type Message struct {
	Type string `json:"type"`
	Data Object `json:"data"`
}

Message represents websocket message.

type Object

type Object map[string]interface{}

Object represents generic message parameters.

type Server

type Server struct {
	App *App
	// contains filtered or unexported fields
}

Server contains options and methods for running zero-copy websocket server on straight TCP connection. Use in a combination of UpstreamHandler.

func New

func New(config *config.Config, logger *zap.Logger) *Server

New initializes and returns a new websocket server instance.

func (*Server) Run

func (s *Server) Run() error

Run starts the websocket server.

Jump to

Keyboard shortcuts

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