ws

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: MIT, MIT Imports: 8 Imported by: 0

README

socklace

Websockets stuff

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPacket = errors.New("ws: invalid packet")
View Source
var ErrUnknownHandler = errors.New("ws: unknown handler")

Functions

This section is empty.

Types

type Connection

type Connection struct {
	Request *http.Request
	Values  sync.Map
	// contains filtered or unexported fields
}

Connection holds all data and websocket connection

func (*Connection) Context

func (conn *Connection) Context() context.Context

func (*Connection) Send

func (conn *Connection) Send(id int64, topic string, data interface{}) error

type Hook

type Hook func(conn *Connection)

Hook is function called before main loop or after connection was closed

type Request

type Request struct {
	C *Connection `json:"-"`

	ID    int64
	Topic string
	Data  json.RawMessage
}

Request represents data sends from client to server

func (*Request) Respond

func (r *Request) Respond(data interface{}) error

Respond sends response to client and returns error if failed

type WS

type WS interface {
	// RegisterHandler register function for entered topic
	// note that handlerFn is interface{} but should be function (func(r *Request, optionalParameter string))
	RegisterHandler(topic string, handlerFn interface{})

	//AddPreHook appends pre main loop hook
	AddPreHook(hook Hook)

	//AddPostHook appends post request hook
	AddPostHook(hook Hook)

	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

func NewWS

func NewWS(upgrader *websocket.Upgrader, errorHandler func(*Connection, error)) WS

Directories

Path Synopsis
hooks
ping
Package ping provides hook for pinging websocket every 5 seconds TODO: Add configuration
Package ping provides hook for pinging websocket every 5 seconds TODO: Add configuration

Jump to

Keyboard shortcuts

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