websocket

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferPoolKey

type BufferPoolKey struct{}

type CheckOriginKey

type CheckOriginKey struct{}

type Connection

type Connection struct {
	Socket   *websocket.Conn
	ChRead   chan *ReadMessage
	ChWrite  chan interface{}
	IsClosed bool
	ChClose  chan struct{}
}

func (*Connection) Close

func (conn *Connection) Close() error

func (*Connection) Read

func (conn *Connection) Read() *ReadMessage

func (*Connection) ReadLoop

func (conn *Connection) ReadLoop()

func (*Connection) Write

func (conn *Connection) Write(data interface{})

func (*Connection) WriteLoop

func (conn *Connection) WriteLoop()

type ErrorKey

type ErrorKey struct{}

type Option

type Option func(*Options)

func WithCheckOrigin

func WithCheckOrigin(checkOrigin func(r *http.Request) bool) Option

func WithEnableCompression

func WithEnableCompression(enableCompression bool) Option

func WithError

func WithError(err func(w http.ResponseWriter, r *http.Request, status int, reason error)) Option

func WithHandshakeTimeout

func WithHandshakeTimeout(handshakeTimeout time.Duration) Option

func WithReadBufferSize

func WithReadBufferSize(readBuffSize int) Option

func WithSubprotocols

func WithSubprotocols(subProtocols []string) Option

func WithWriteBufferPool

func WithWriteBufferPool(writeBufferPool websocket.BufferPool) Option

func WithWriteBufferSize

func WithWriteBufferSize(writeBuffSize int) Option

type Options

type Options struct {
	HandshakeTimeout time.Duration

	ReadBufferSize, WriteBufferSize int

	WriteBufferPool websocket.BufferPool

	Subprotocols []string

	Error func(w http.ResponseWriter, r *http.Request, status int, reason error)

	CheckOrigin func(r *http.Request) bool

	EnableCompression bool
}

type ReadMessage

type ReadMessage struct {
	MsgType int
	Msg     []byte
}

type Websocket

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

func New

func New(opts ...Option) *Websocket

func (*Websocket) AddConnection

func (ws *Websocket) AddConnection(key interface{}, conn *Connection)

func (*Websocket) Exist

func (ws *Websocket) Exist(key interface{}) bool

func (*Websocket) GetConnection

func (ws *Websocket) GetConnection(key interface{}) (*Connection, bool)

func (*Websocket) Provide

func (ws *Websocket) Provide(ctx context.Context) interface{}

func (*Websocket) RemoveConnection

func (ws *Websocket) RemoveConnection(key interface{})

func (*Websocket) Upgrade

func (ws *Websocket) Upgrade(key interface{}, w http.ResponseWriter, r *http.Request, respHeader http.Header) (*Connection, error)

Jump to

Keyboard shortcuts

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