websocket

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Time allowed to write a message to the peer.
	WriteWait = 10 * time.Second
	// Time allowed to read the next pong message from the peer.
	PongWait = 60 * time.Second
	// Send pings to peer with this period. Must be less than pongWait.
	PingPeriod = (PongWait * 9) / 10
	// Maximum message size allowed from peer.
	MaxMessageSize int64 = 64 * 1024
)

Functions

func Upgrade

func Upgrade(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)

Types

type Client

type Client struct {
	ID   string
	Conn *websocket.Conn
	Pool *Pool
	Send chan interface{}
	// contains filtered or unexported fields
}

func NewClient added in v1.0.0

func NewClient(id string, conn *websocket.Conn, pool *Pool) *Client

func (*Client) NewPublishRequest

func (c *Client) NewPublishRequest(m map[string]interface{}) *PublishRequest

func (*Client) NewSubscribeRequest

func (c *Client) NewSubscribeRequest(m map[string]interface{}) *SubscribeRequest

func (*Client) ReadListen added in v1.0.0

func (c *Client) ReadListen()

func (*Client) WriteListen added in v1.0.0

func (c *Client) WriteListen()

type CloudEvent

type CloudEvent struct {
	ID              string                 `json:"id"`
	Source          string                 `json:"source"`
	Type            string                 `json:"type"`
	Data            map[string]interface{} `json:"data"`
	DataContentType string                 `json:"datacontenttype"`
	Time            int                    `json:"time"`
	SpecVersion     string                 `json:"specversion"`
	Meta            map[string]interface{} `json:"meta"`
}

CloudEvent - https://github.com/cloudevents/spec/blob/v1.0.1/spec.md

type Message

type Message interface {
	// contains filtered or unexported methods
}

Message - Message duck type

type Pool

type Pool struct {
	Subscribe      chan SubscribeRequest
	Unsubscribe    chan SubscribeRequest
	UnsubscribeAll chan SubscribeRequest
	Publish        chan PublishRequest
	Subs           map[string]*Sub
	Logging        *logging.Logger
}

Pool - Shared worker pool resources

func NewPool

func NewPool(logger *logging.Logger) *Pool

NewPool - Creates new instance of Pool

func (*Pool) CacheManager added in v1.0.0

func (p *Pool) CacheManager()

CacheManager - Managers servers cache TODO: CacheManager

func (*Pool) Start

func (p *Pool) Start()

Start - Go Routine runs worker with shared Pool resources.

func (*Pool) TakeSnapshot added in v1.0.0

func (p *Pool) TakeSnapshot()

TakeSnapshot - Takes Snapshot of Current State of Subscriptions. TODO: CacheManager

type PublishEvent

type PublishEvent struct {
	Type     string     `json:"type"`
	Channels []string   `json:"channels"`
	Event    CloudEvent `json:"event"`
}

PublishEvent - Publish incoming message type

func NewPublishEvent

func NewPublishEvent(m map[string]interface{}) *PublishEvent

type PublishRequest

type PublishRequest struct {
	PublishEvent
	Client *Client
}

type Sub added in v1.0.0

type Sub struct {
	ID string
	// contains filtered or unexported fields
}

Sub - Represents a Subscription

func NewSub added in v1.0.0

func NewSub(id string, channels []string, client *Client) *Sub

NewSub - Creates an instance of Sub

func (*Sub) AddClient added in v1.0.0

func (s *Sub) AddClient(client *Client)

AddClient - Thread Safe method of adding a client to Sub

func (*Sub) AddNewChannels added in v1.0.0

func (s *Sub) AddNewChannels(channels []string)

AddNewChannels - Thread Safe method of adding new channels to Sub

func (*Sub) RemoveChannels added in v1.0.0

func (s *Sub) RemoveChannels(channels []string)

RemoveChannels - Thread Safe method of removing channels from Sub

type SubscribeMessage

type SubscribeMessage struct {
	Type     string   `json:"type"`
	Channels []string `json:"channels"`
}

SubscribeMessage - Subscribe incoming message type

func NewSubscribeMessage

func NewSubscribeMessage(m map[string]interface{}) *SubscribeMessage

type SubscribeRequest

type SubscribeRequest struct {
	SubscribeMessage
	Client *Client
}

Jump to

Keyboard shortcuts

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