pubsub

package
v0.0.0-...-2269230 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PUBLISH     = "publish"
	UNSUBSCRIBE = "unsubscribe"
	SUBSCRIBE   = "subscribe"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ID         string
	Connection *websocket.Conn
}

Client - struct

func (*Client) Send

func (c *Client) Send(message []byte) error

Send - send message pub/sub

type Message

type Message struct {
	Action  string          `json:"action"`
	Topic   string          `json:"topic"`
	Message json.RawMessage `json:"message"`
}

Message - struct

type PubSub

type PubSub struct {
	Clients       []Client
	Subscriptions []Subscription
}

PubSub - struct

func (*PubSub) AddClient

func (ps *PubSub) AddClient(c Client) *PubSub

AddClient - struct add new Client

func (*PubSub) GetSubscriptions

func (ps *PubSub) GetSubscriptions(topic string, client *Client) []Subscription

GetSubscriptions - client

func (*PubSub) HandleReceiveMessage

func (ps *PubSub) HandleReceiveMessage(c Client, messageType int, message []byte) *PubSub

HandleReceiveMessage - struct

func (*PubSub) Publish

func (ps *PubSub) Publish(topic string, message []byte, excludeClient *Client)

Publish - ps topic publish

func (*PubSub) RemoveClient

func (ps *PubSub) RemoveClient(c Client) *PubSub

RemoveClient - remove subscription and client pub/sub

func (*PubSub) Subscribe

func (ps *PubSub) Subscribe(client *Client, topic string) *PubSub

Subscribe - function handler Subscribe

func (*PubSub) Unsubscribe

func (ps *PubSub) Unsubscribe(c *Client, topic string) *PubSub

Unsubscribe - handler unsubscribes

type Subscription

type Subscription struct {
	Topic  string
	Client *Client
}

Subscription - struct

Jump to

Keyboard shortcuts

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