ws

package
v0.0.0-...-fc9f681 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2021 License: MIT, MIT Imports: 8 Imported by: 1

README

socklace

Websockets stuff

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func SM

func SM(success bool, message string) sm

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 struct {
	ErrorHandler func(c *Connection, err error)
	Upgrader     websocket.Upgrader
	// contains filtered or unexported fields
}

func (*WS) AddPostHook

func (m *WS) AddPostHook(hook Hook)

AddPostHook appends post request hook

func (*WS) AddPreHook

func (m *WS) AddPreHook(hook Hook)

AddPreHook appends pre main loop hook

func (*WS) RegisterHandler

func (m *WS) RegisterHandler(topic string, handlerFn interface{})

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

func (*WS) ServeHTTP

func (m *WS) ServeHTTP(w http.ResponseWriter, r *http.Request)

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