hub

package
v0.0.0-...-60e4288 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	TopicsLock  sync.RWMutex
	Topics      map[string]*Topic
	Broadcast   chan Message
	Subscribe   chan Subscription
	UnSubscribe chan Subscription
}

func New

func New() *Hub

func (*Hub) HasUser

func (h *Hub) HasUser(topicID string, user string) bool

func (*Hub) SendMsgTo

func (h *Hub) SendMsgTo(topicID, user string, msgType int, data []byte)

func (*Hub) Serialize

func (h *Hub) Serialize(topicID string, skip string) TopicSerialize

func (*Hub) Serve

func (h *Hub) Serve()

func (*Hub) UpdateLang

func (h *Hub) UpdateLang(topicID string, lang string)

type Message

type Message struct {
	Data  interface{}
	Topic string
	From  string
}

type Subscription

type Subscription struct {
	Conn  *websocket.Conn
	User  string
	Topic string
}

type Topic

type Topic struct {
	Conns map[string]*websocket.Conn
	Lang  string
	Lock  sync.Mutex
}

type TopicSerialize

type TopicSerialize struct {
	Lang string   `json:"lang,omitempty"`
	User []string `json:"user,omitempty"`
}

Jump to

Keyboard shortcuts

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