websocket

package
v0.0.0-...-82c6a1a Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const GoingAwayMessage = -1

GoingAwayMessage - uses when connection was aborted.

View Source
const TextMessage = 1

TextMessage - uses when message is correct.

Variables

This section is empty.

Functions

func EncodeEvent

func EncodeEvent(e *Event) []byte

EncodeEvent - encode event to message

Types

type Bus

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

func NewRequest

func NewRequest(cp *ConnectionPool, cId int) *Bus

NewRequest - creator for new request.

func (*Bus) ConnectionDelete

func (r *Bus) ConnectionDelete()

ConnectionDelete - delete current connection.

func (*Bus) ConnectionId

func (r *Bus) ConnectionId() int

ConnectionId - getter for current connection id.

func (*Bus) ConnectionPool

func (r *Bus) ConnectionPool() *ConnectionPool

ConnectionPool - getter for connection pool.

func (*Bus) ConnectionPoolWriteEvent

func (r *Bus) ConnectionPoolWriteEvent(e *Event)

ConnectionPoolWriteEvent - write event into connection pool.

func (*Bus) ConnectionReadEvent

func (r *Bus) ConnectionReadEvent() (int, *Event)

ConnectionReadEvent - read event from current connection.

func (*Bus) ConnectionWriteEvent

func (r *Bus) ConnectionWriteEvent(e *Event)

ConnectionWriteEvent - write event into current connection.

type ConnectionCollection

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

ConnectionCollection - collection of client websocket connections. Represent interface of one client websocket.

func NewConnectionCollection

func NewConnectionCollection(c map[int]*websocket.Conn) *ConnectionCollection

NewConnectionCollection - instantiate new connection collection.

func (*ConnectionCollection) WriteMessage

func (cc *ConnectionCollection) WriteMessage(messageType int, data []byte)

WriteMessage - write same message to each connection.

type ConnectionPool

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

ConnectionPool - pool of client websocket connections.

func NewConnectionPool

func NewConnectionPool() *ConnectionPool

NewConnectionPool - instantiate new connection pool.

func (*ConnectionPool) Count

func (cp *ConnectionPool) Count() int

Count - count connections in pool.

func (*ConnectionPool) Delete

func (cp *ConnectionPool) Delete(id int)

Delete - delete one connection in the pool.

func (*ConnectionPool) Get

func (cp *ConnectionPool) Get(id int) *websocket.Conn

Get - get one connection from the pool.

func (*ConnectionPool) GetAll

func (cp *ConnectionPool) GetAll() *ConnectionCollection

GetAll - get all connections from the pool.

func (*ConnectionPool) Push

func (cp *ConnectionPool) Push(c *websocket.Conn) int

Push - add new connection into the pool.

type Event

type Event struct {
	Op   string
	Data EventData
}

Event structure for exchange by websocket.

func DecodeMessage

func DecodeMessage(message []byte) Event

DecodeMessage - DecodeMessage event from message

func NewEvent

func NewEvent(op string, d EventData) *Event

NewEvent - creates new event.

type EventData

type EventData map[string]any

type EventOperation

type EventOperation string

type Upgrader

type Upgrader struct {
	websocket.Upgrader
}

Upgrader - custom upgrader structure.

func NewUpgrader

func NewUpgrader() *Upgrader

NewUpgrader - instantiate new upgrader.

func (*Upgrader) CheckOriginFunc

func (u *Upgrader) CheckOriginFunc(handleFunc func(r *http.Request) bool)

CheckOriginFunc - uses for checking request origin. Can be used to identify client.

func (*Upgrader) UpgradeConnection

func (u *Upgrader) UpgradeConnection(w http.ResponseWriter, r *http.Request) *websocket.Conn

UpgradeConnection - establish new connection.

Jump to

Keyboard shortcuts

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