websocket

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ConnectionHandler
	WriteWait time.Duration
}

Client that is able to connect to a websocket server

func NewClient

func NewClient(co service.Container) (c *Client, err error)

NewClient constructor

func (*Client) BroadcastJSON

func (c *Client) BroadcastJSON(name string, t route.Type, data interface{}, filter func(*Connection) bool)

BroadcastJSON broadcast data to all connections (can be filtered)

func (*Client) Connect

func (c *Client) Connect(u url.URL, lang *language.Tag) (conn *Connection, err error)

Connect to a websocket server

type Connection

type Connection struct {
	Context route.RequestContext
	// contains filtered or unexported fields
}

Connection interface

func NewClientConnection

func NewClientConnection(ch ConnectionHandler, conn *gorilla.Conn, lang *language.Tag) (c *Connection)

NewClientConnection instance creation

func NewServerConnection

func NewServerConnection(ch ConnectionHandler, conn *gorilla.Conn, lang *language.Tag) (c *Connection)

NewServerConnection instance creation

func (*Connection) SendJSON

func (c *Connection) SendJSON(route string, t route.Type, data interface{}) (err error)

SendJSON data over the websocket

type ConnectionEvents

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

ConnectionEvents event handlers for connections

func (*ConnectionEvents) AfterRequest

func (e *ConnectionEvents) AfterRequest(tx *storage.Transaction) (err error)

AfterRequest hook registration

func (*ConnectionEvents) BeforeRequest

func (e *ConnectionEvents) BeforeRequest(ctx route.RequestContext, msg *JSONMessage) (cancelConnection bool, err error)

BeforeRequest hook registration

func (*ConnectionEvents) CreateRequest

func (e *ConnectionEvents) CreateRequest(conn *Connection, tx *storage.Transaction) (r route.Request)

CreateRequest event trigger

func (*ConnectionEvents) NewConnection

func (e *ConnectionEvents) NewConnection(c *Connection, uctx UpgradeContext) (err error)

NewConnection event trigger

func (*ConnectionEvents) OnAfterRequest

func (e *ConnectionEvents) OnAfterRequest(fn OnAfterRequest)

OnAfterRequest hook registration

func (*ConnectionEvents) OnBeforeRequest

func (e *ConnectionEvents) OnBeforeRequest(fn OnBeforeRequest)

OnBeforeRequest hook registration

func (*ConnectionEvents) OnCreateRequest

func (e *ConnectionEvents) OnCreateRequest(fn OnCreateRequest)

OnCreateRequest hook registration

func (*ConnectionEvents) OnNewConnection

func (e *ConnectionEvents) OnNewConnection(fn OnNewConnection)

OnNewConnection hook registration

type ConnectionHandler

type ConnectionHandler struct {
	service.Container
	route.Grouper
	ConnectionEvents
	// contains filtered or unexported fields
}

ConnectionHandler base type

func CreateConnectionHandler

func CreateConnectionHandler(c service.Container, isServer bool) (h ConnectionHandler)

CreateConnectionHandler helper

func (*ConnectionHandler) GetHandler

func (ch *ConnectionHandler) GetHandler(msg *JSONMessage) (middleware []route.Middleware, h route.Handler)

GetHandler for a request

func (*ConnectionHandler) Stop

func (ch *ConnectionHandler) Stop()

Stop the client

type GetHandlerFunc

type GetHandlerFunc func(data *JSONMessage) (middleware []route.Middleware, h route.Handler)

GetHandlerFunc :

type HTTPContext

type HTTPContext struct {
	Writer         netHttp.ResponseWriter
	Request        *netHttp.Request
	ResponseHeader netHttp.Header
}

HTTPContext for http upgrade

type JSONMessage

type JSONMessage struct {
	Route     string     `json:"r"`
	Type      route.Type `json:"t"`
	Payload   string     `json:"p"`
	AuthToken string     `json:"a,omitempty"`
}

JSONMessage is sent via a websocket

type Message

type Message struct {
	Name   string
	T      route.Type
	Data   interface{}
	Filter func(*Connection) bool
}

Message to be sent via a websocket connection

type OnAfterRequest

type OnAfterRequest func(tx *storage.Transaction) (err error)

OnAfterRequest hook

type OnBeforeRequest

type OnBeforeRequest func(ctx route.RequestContext, msg *JSONMessage) (cancelConnection bool, err error)

OnBeforeRequest hook

type OnCreateRequest

type OnCreateRequest func(conn *Connection, tx *storage.Transaction) (r route.Request)

OnCreateRequest hook

type OnNewConnection

type OnNewConnection func(c *Connection, uctx UpgradeContext) (err error)

OnNewConnection hook

type RequestContext

type RequestContext struct {
	route.BaseRequestContext
}

RequestContext of a connection

type Server

type Server struct {
	ConnectionHandler
	// contains filtered or unexported fields
}

Server for a websocket api

func NewServer

func NewServer(config *ServerConfig, co service.Container) (s *Server, err error)

NewServer instance creation

func (*Server) BroadcastJSON

func (s *Server) BroadcastJSON(name string, t route.Type, data interface{}, filter func(*Connection) bool)

BroadcastJSON broadcast data to all connections (can be filtered)

func (*Server) UpgradeConnection

func (s *Server) UpgradeConnection(ctx UpgradeContext) (err error)

UpgradeConnection http to a websocket connection

func (*Server) UpgradeHandler

func (s *Server) UpgradeHandler(server *netHttp.Server) route.HandlerGenerator

UpgradeHandler returns a handler that upgrades a http connection to a websocket connection that is handled by this server

type ServerConfig

type ServerConfig struct {
	Upgrader       *gorilla.Upgrader
	WriteWait      time.Duration
	PongWait       time.Duration
	PingInterval   time.Duration
	MaxMessageSize int64
}

ServerConfig of the api

type UpgradeContext

type UpgradeContext interface {
	HTTPContext() (ctx *HTTPContext)
	Language() (lang *language.Tag)
}

UpgradeContext is used to upgrade http to websocket

Jump to

Keyboard shortcuts

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