ws

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CloseNormalClosure indicates normal closure
	CloseNormalClosure = websocket.CloseNormalClosure

	// CloseInternalServerErr indicates closure because of internal error
	CloseInternalServerErr = websocket.CloseInternalServerErr

	// CloseAbnormalClosure indicates abnormal close
	CloseAbnormalClosure = websocket.CloseAbnormalClosure

	// CloseGoingAway indicates closing because of server shuts down or client disconnects
	CloseGoingAway = websocket.CloseGoingAway
)

Variables

This section is empty.

Functions

func CheckOrigin

func CheckOrigin(origins string) func(r *http.Request) bool

func CloseWithReason

func CloseWithReason(ws *websocket.Conn, code int, reason string)

CloseWithReason closes WebSocket connection with the specified close code and reason

func IsCloseError

func IsCloseError(err error) bool

func WebsocketHandler

func WebsocketHandler(subprotocols []string, headersExtractor server.HeadersExtractor, config *Config, l *slog.Logger, sessionHandler sessionHandler) http.Handler

WebsocketHandler generate a new http handler for WebSocket connections

Types

type Config

type Config struct {
	ReadBufferSize    int
	WriteBufferSize   int
	MaxMessageSize    int64
	EnableCompression bool
	AllowedOrigins    string
}

Config contains WebSocket connection configuration.

func NewConfig

func NewConfig() Config

NewConfig build a new Config struct

type Connection

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

Connection is a WebSocket implementation of Connection

func NewConnection

func NewConnection(conn *websocket.Conn) *Connection

func (Connection) Close

func (ws Connection) Close(code int, reason string)

Close sends close frame with a given code and a reason

func (Connection) Read

func (ws Connection) Read() ([]byte, error)

func (Connection) Write

func (ws Connection) Write(msg []byte, deadline time.Time) error

Write writes a text message to a WebSocket

func (Connection) WriteBinary

func (ws Connection) WriteBinary(msg []byte, deadline time.Time) error

WriteBinary writes a binary message to a WebSocket

type FrameType

type FrameType int
const (
	TextFrame   FrameType = 0
	CloseFrame  FrameType = 1
	BinaryFrame FrameType = 2
)

type SentFrame

type SentFrame struct {
	FrameType   FrameType
	Payload     []byte
	CloseCode   int
	CloseReason string
}

Jump to

Keyboard shortcuts

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