Documentation ¶
Index ¶
- Constants
- func AddClient(s *SSEPubSubService, w http.ResponseWriter, r *http.Request)
- func AddPrivateTopic(s *SSEPubSubService, w http.ResponseWriter, r *http.Request)
- func AddPublicTopic(s *SSEPubSubService, w http.ResponseWriter, r *http.Request)
- func Event(s *SSEPubSubService, w http.ResponseWriter, r *http.Request)
- func Subscribe(s *SSEPubSubService, w http.ResponseWriter, r *http.Request)
- func Unsubscribe(s *SSEPubSubService, w http.ResponseWriter, r *http.Request)
- type Client
- func (c *Client) GetAllTopics() map[string]*Topic
- func (c *Client) GetGroupByName(name string) (*Group, bool)
- func (c *Client) GetGroups() map[string]*Group
- func (c *Client) GetID() string
- func (c *Client) GetPrivateTopicByName(name string) (*Topic, bool)
- func (c *Client) GetPrivateTopics() map[string]*Topic
- func (c *Client) GetPublicTopicByName(name string) (*Topic, bool)
- func (c *Client) GetPublicTopics() map[string]*Topic
- func (c *Client) GetStatus() status
- func (c *Client) GetSubscribedTopics() map[string]*Topic
- func (c *Client) GetTopicByName(name string) (*Topic, bool)
- func (c *Client) NewPrivateTopic(name string) *Topic
- func (c *Client) RemovePrivateTopic(t *Topic)
- func (c *Client) Start(ctx context.Context, onEvent OnEventFunc) error
- func (c *Client) Sub(topic *Topic) error
- func (c *Client) Unsub(topic *Topic) error
- type Group
- func (g *Group) AddClient(c *Client)
- func (g *Group) GetClientByID(id string) (*Client, bool)
- func (g *Group) GetClients() map[string]*Client
- func (g *Group) GetID() string
- func (g *Group) GetName() string
- func (g *Group) GetTopicByName(name string) (*Topic, bool)
- func (g *Group) GetTopics() map[string]*Topic
- func (g *Group) NewTopic(name string) *Topic
- func (g *Group) RemoveClient(c *Client)
- func (g *Group) RemoveTopic(t *Topic)
- type OnEventFunc
- type SSEPubSubService
- func (s *SSEPubSubService) GetClientByID(id string) (*Client, bool)
- func (s *SSEPubSubService) GetClients() map[string]*Client
- func (s *SSEPubSubService) GetGroupByName(name string) (*Group, bool)
- func (s *SSEPubSubService) GetGroups() map[string]*Group
- func (s *SSEPubSubService) GetPublicTopicByName(name string) (*Topic, bool)
- func (s *SSEPubSubService) GetPublicTopics() map[string]*Topic
- func (s *SSEPubSubService) NewClient() *Client
- func (s *SSEPubSubService) NewGroup(name string) *Group
- func (s *SSEPubSubService) NewPublicTopic(name string) *Topic
- func (s *SSEPubSubService) OnNewClient(f funcClient) string
- func (s *SSEPubSubService) RemoveClient(c *Client)
- func (s *SSEPubSubService) RemoveGroup(g *Group)
- func (s *SSEPubSubService) RemoveOnNewClient(id string)
- func (s *SSEPubSubService) RemovePublicTopic(t *Topic)
- type Topic
Constants ¶
const ( Waiting status = iota Receving )
const ( TPublic topicType = "public" TPrivate topicType = "private" TGroup topicType = "group" )
Variables ¶
This section is empty.
Functions ¶
func AddClient ¶
func AddClient(s *SSEPubSubService, w http.ResponseWriter, r *http.Request)
AddClient handles HTTP requests for adding a new client.
func AddPrivateTopic ¶
func AddPrivateTopic(s *SSEPubSubService, w http.ResponseWriter, r *http.Request)
AddPrivateTopic handles HTTP requests for adding a new private topic.
func AddPublicTopic ¶
func AddPublicTopic(s *SSEPubSubService, w http.ResponseWriter, r *http.Request)
AddPublicTopic handles HTTP requests for adding a new public topic.
func Subscribe ¶
func Subscribe(s *SSEPubSubService, w http.ResponseWriter, r *http.Request)
Subscribe handles HTTP requests for client subscriptions.
func Unsubscribe ¶
func Unsubscribe(s *SSEPubSubService, w http.ResponseWriter, r *http.Request)
Unsubscribe handles HTTP requests for client unsubscriptions.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a subscriber with a channel to send messages.
func (*Client) GetGroupByName ¶
Get group by name
func (*Client) GetPrivateTopicByName ¶
Get private topic by name
func (*Client) GetPrivateTopics ¶
Get private topics
func (*Client) GetPublicTopicByName ¶
Get public topic by name
func (*Client) GetPublicTopics ¶
Get public topics
func (*Client) GetSubscribedTopics ¶
Get subscribed topics
func (*Client) GetTopicByName ¶
Get topic by name
func (*Client) NewPrivateTopic ¶
New private topic 0. Check if topic already exists, return it if it does 1. Create a new private topic 2. Add the topic to the client 3. Inform the client about the new topic
func (*Client) RemovePrivateTopic ¶
Remove private topic 0. Check if topic exists, return error if it does not 1. Unsubscribe from the topic 2. Remove the topic from the client 3. Inform the client about the removed topic by sending the new topic list
func (*Client) Start ¶
func (c *Client) Start(ctx context.Context, onEvent OnEventFunc) error
Start the client 0. Check if client is already receiving 1. Set status to Receving and create stop channel 2. Send init message to client 3. Keep the connection open 4. Send message to client if new data is published over the stream 5. Stop the client if the stop channel is closed
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a collection of topics.
func (*Group) AddClient ¶
AddClient adds a client to the group. 0. Check if client already exists in the group 1. Add client to the group 2. Add group to client
func (*Group) GetClientByID ¶
Get client by ID
func (*Group) GetClients ¶
GetClients returns a map of clients.
func (*Group) GetTopicByName ¶
Get topic by name
func (*Group) NewTopic ¶
AddTopic adds a topic to the group. 1. Check if topic already exists, return it if it does 2. Add the topic to the group 3. Inform all clients about the new topic
func (*Group) RemoveClient ¶
RemoveClient removes a client from the group. 0. Check if client exists in the group 1. Unsubscribe client from all group topics 2. Remove client from the group 3. Remove group from client 4. Inform client about the removed topic
func (*Group) RemoveTopic ¶
RemoveTopic removes a topic from the group. 0. Check if topic is a group topic 1. Check if topic exists in the group 2. Unsuscribe all clients from the topic 3. Remove topic from the group 4. Inform all clients about the removed topic
type OnEventFunc ¶
type OnEventFunc func(string)
type SSEPubSubService ¶
type SSEPubSubService struct {
// contains filtered or unexported fields
}
SSEPubSubService represents the SSE publisher and subscriber system.
func NewSSEPubSubService ¶
func NewSSEPubSubService() *SSEPubSubService
NewSSEPubSub creates a new sSEPubSubService instance.
func (*SSEPubSubService) GetClientByID ¶
func (s *SSEPubSubService) GetClientByID(id string) (*Client, bool)
Get client by ID
func (*SSEPubSubService) GetClients ¶
func (s *SSEPubSubService) GetClients() map[string]*Client
Get clients
func (*SSEPubSubService) GetGroupByName ¶
func (s *SSEPubSubService) GetGroupByName(name string) (*Group, bool)
Get group by name
func (*SSEPubSubService) GetGroups ¶
func (s *SSEPubSubService) GetGroups() map[string]*Group
Get groups
func (*SSEPubSubService) GetPublicTopicByName ¶
func (s *SSEPubSubService) GetPublicTopicByName(name string) (*Topic, bool)
Get public topic by name
func (*SSEPubSubService) GetPublicTopics ¶
func (s *SSEPubSubService) GetPublicTopics() map[string]*Topic
Get public topics
func (*SSEPubSubService) NewClient ¶
func (s *SSEPubSubService) NewClient() *Client
Create new client
func (*SSEPubSubService) NewGroup ¶
func (s *SSEPubSubService) NewGroup(name string) *Group
Add Group 0. Check if group already exists, return it if it does 1. Create a new group 2. Add the group to the sSEPubSubService
func (*SSEPubSubService) NewPublicTopic ¶
func (s *SSEPubSubService) NewPublicTopic(name string) *Topic
Create new public topic 0. Check if topic already exists, return it if it does 1. Create a new public topic 2. Add the topic to the sSEPubSubService 3. Inform all clients about the new topic
func (*SSEPubSubService) OnNewClient ¶
func (s *SSEPubSubService) OnNewClient(f funcClient) string
Event: When client is created
func (*SSEPubSubService) RemoveClient ¶
func (s *SSEPubSubService) RemoveClient(c *Client)
Remove client 1. Unsubscribe from all topics 2. Remove all private topics 3. Stop the client 4. Remove client from sSEPubSubService
func (*SSEPubSubService) RemoveGroup ¶
func (s *SSEPubSubService) RemoveGroup(g *Group)
Remove group 0. Check if group exists in sSEPubSubService 1. Remove all topics from the group 2. Remove all clients from the group 3. Remove group from sSEPubSubService
func (*SSEPubSubService) RemoveOnNewClient ¶
func (s *SSEPubSubService) RemoveOnNewClient(id string)
Remove Event: When client is created
func (*SSEPubSubService) RemovePublicTopic ¶
func (s *SSEPubSubService) RemovePublicTopic(t *Topic)
Remove public topic 0. Check if topic is public 1. Unsubscribe all clients from the topic 2. Check if topic exists in sSEPubSubService 3. Remove topic from sSEPubSubService 4. Inform all clients about the removed topic by sending the new topic list
type Topic ¶
type Topic struct {
// contains filtered or unexported fields
}
Topic represents a messaging Topic in the SSE pub-sub system.
func (*Topic) GetClients ¶
Get all clients in the topic
func (*Topic) IsSubscribed ¶
Check if a client is subscribed to the topic