Documentation
¶
Index ¶
- type IPubSub
- type ISubscriber
- type Message
- type OnNotifyFn
- type PubSub
- func (b *PubSub) AddSubscriber(conn *SubscriberConnectionOpts) *Subscriber
- func (b *PubSub) Broadcast(msg string)
- func (b *PubSub) CountTopicSubscribers(topic string) int
- func (b *PubSub) Publish(topics []string, msg string)
- func (b *PubSub) RemoveSubscriber(conn *SubscriberConnectionOpts) *Subscriber
- func (b *PubSub) Sub(topics []string, conn *SubscriberConnectionOpts)
- func (b *PubSub) Unsub(topics []string, conn *SubscriberConnectionOpts)
- type Subscriber
- func (s *Subscriber) AddTopic(topic string)
- func (s *Subscriber) AddTopics(topics []string)
- func (s *Subscriber) Destroy()
- func (s *Subscriber) GetID() string
- func (s *Subscriber) GetSubID() string
- func (s *Subscriber) GetTopics() []string
- func (s *Subscriber) GetUID() string
- func (s *Subscriber) Listen()
- func (s *Subscriber) Notify(msg *Message)
- func (s *Subscriber) RegisterNotifyHandler(h OnNotifyFn)
- func (s *Subscriber) RemoveTopic(topic string)
- type SubscriberConnectionOpts
- type Subscribers
- type Topics
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IPubSub ¶
type IPubSub interface {
AddSubscriber(conn *SubscriberConnectionOpts) *Subscriber
RemoveSubscriber(conn *SubscriberConnectionOpts) *Subscriber
CountTopicSubscribers(topic string) int
Sub(topics []string, conn *SubscriberConnectionOpts)
Unsub(topics []string, conn *SubscriberConnectionOpts)
Publish(topic []string, msg string)
Broadcast(msg string)
}
IPubSub represents abstract PubSub for topic notifications
type ISubscriber ¶
type ISubscriber interface {
GetSubID() string
GetID() string
GetUID() string
AddTopic(topic string)
AddTopics(topics []string)
RemoveTopic(topic string)
GetTopics() []string
Destroy()
Notify(msg *Message)
Listen()
}
ISubscriber represents topic(-s) subscriber
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message represent text notification for topic
func NewMessage ¶
NewMessage create new text message for topic
func (Message) GetMessagePayload ¶
GetMessagePayload return message payload
type OnNotifyFn ¶
type OnNotifyFn = func(conn *SubscriberConnectionOpts, msg *Message)
OnNotifyFn callback func for notifications
type PubSub ¶
type PubSub struct {
// contains filtered or unexported fields
}
PubSub implement abstraction for notifications
func (*PubSub) AddSubscriber ¶
func (b *PubSub) AddSubscriber(conn *SubscriberConnectionOpts) *Subscriber
AddSubscriber by unique id (for example, ws for connection could be "conn_id:user_id")
func (*PubSub) CountTopicSubscribers ¶
CountTopicSubscribers count of active topic subs
func (*PubSub) RemoveSubscriber ¶
func (b *PubSub) RemoveSubscriber(conn *SubscriberConnectionOpts) *Subscriber
RemoveSubscriber remove by unique id
func (*PubSub) Sub ¶
func (b *PubSub) Sub(topics []string, conn *SubscriberConnectionOpts)
Sub user to topic
func (*PubSub) Unsub ¶
func (b *PubSub) Unsub(topics []string, conn *SubscriberConnectionOpts)
Unsub user to topic
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
Subscriber wrapper
func NewSubscriber ¶
func NewSubscriber(conn *SubscriberConnectionOpts) *Subscriber
NewSubscriber create new default subscriber
func (*Subscriber) AddTopics ¶
func (s *Subscriber) AddTopics(topics []string)
AddTopics sub to topics
func (*Subscriber) Destroy ¶
func (s *Subscriber) Destroy()
Destroy clear sub (topics, close channels)
func (*Subscriber) GetTopics ¶
func (s *Subscriber) GetTopics() []string
GetTopics return all topics
func (*Subscriber) RegisterNotifyHandler ¶
func (s *Subscriber) RegisterNotifyHandler(h OnNotifyFn)
RegisterNotifyHandler attach notification handler
func (*Subscriber) RemoveTopic ¶
func (s *Subscriber) RemoveTopic(topic string)
RemoveTopic unsub topic
type SubscriberConnectionOpts ¶
type SubscriberConnectionOpts struct {
CID string // ws connection uuid
UID string // associated user id
}
SubscriberConnectionOpts represent connection options
func (*SubscriberConnectionOpts) GetSubID ¶
func (s *SubscriberConnectionOpts) GetSubID() string
GetSubID return sub id like uuid:uid
type Subscribers ¶
type Subscribers map[string]*Subscriber
Subscribers map of subs like map[id:Subscriber]
type Topics ¶
type Topics map[string]Subscribers
Topics map of sub's topics like map[topic:map[id:Subscriber]]