wshelper

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2022 License: MIT Imports: 10 Imported by: 2

README

CodeFactor Go Reference

You can find usage example in this directory.

These are a tools for a nhooyr.io/websocket library.

We are using a ksuid library for UUID.

Documentation

Overview

Simple tools for nhooyr websockets with intuitive API (in golang)

Index

Constants

This section is empty.

Variables

View Source
var (
	Accept = func(w http.ResponseWriter, r *http.Request, opts *websocket.AcceptOptions) (*Connection, error) {
		conn, err := websocket.Accept(w, r, opts)
		if err != nil {
			return nil, err
		}
		return NewConnection(conn), nil
	}
	Dial = func(ctx context.Context, u string, opts *websocket.DialOptions) (*Connection, error) {
		conn, _, err := websocket.Dial(ctx, u, opts)
		if err != nil {
			return nil, err
		}
		return NewConnection(conn), nil
	}
)
View Source
var (
	EmptyCloseHandler = CloseHandler(func(connection *Connection, code websocket.StatusCode, reason string) {})
	EmptyErrorHandler = ErrorHandler(func(connection *Connection, err error) {})
)

Functions

This section is empty.

Types

type CloseHandler

type CloseHandler func(conn *Connection, code websocket.StatusCode, reason string)

type Connection

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

func NewConnection

func NewConnection(conn *websocket.Conn) *Connection

func (*Connection) Close

func (c *Connection) Close(status websocket.StatusCode, reason string) error

func (*Connection) OnClose

func (c *Connection) OnClose(h CloseHandler)

func (*Connection) OnError

func (c *Connection) OnError(h ErrorHandler)

func (*Connection) OnMessage

func (c *Connection) OnMessage(h MessageHandler)

func (*Connection) OnMessageBuffer

func (c *Connection) OnMessageBuffer(h MessageBufferHandler)

func (*Connection) OnMessageReader

func (c *Connection) OnMessageReader(h MessageReaderHandler)

func (*Connection) UUID

func (c *Connection) UUID() string

func (*Connection) WS

func (c *Connection) WS() *websocket.Conn

func (*Connection) Write

func (c *Connection) Write(ctx context.Context, typ websocket.MessageType, data []byte) error

func (*Connection) WriteJSON

func (c *Connection) WriteJSON(ctx context.Context, v interface{}) error

type ErrorHandler

type ErrorHandler func(conn *Connection, err error)

type MessageBufferHandler

type MessageBufferHandler func(conn *Connection, mtype websocket.MessageType, data *bytes.Buffer)

type MessageHandler

type MessageHandler func(conn *Connection, mtype websocket.MessageType, data Payload)

type MessageReaderHandler

type MessageReaderHandler func(conn *Connection, mtype websocket.MessageType, data io.Reader)

type Payload

type Payload []byte

func (Payload) Into

func (p Payload) Into(v interface{}) error

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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