Documentation
¶
Index ¶
- type Client
- type Hub
- func (h *Hub) Broadcast(msg Message) core.Result
- func (h *Hub) ChannelSubscriberCount(channel string) int
- func (h *Hub) ClientCount() int
- func (h *Hub) HandleWebSocket(w http.ResponseWriter, r *http.Request)
- func (h *Hub) Handler() http.HandlerFunc
- func (h *Hub) Run(ctx context.Context)
- func (h *Hub) SendToChannel(channel string, msg Message) core.Result
- func (h *Hub) Subscribe(client *Client, channel string) core.Result
- type Message
- type MessageType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
func (*Hub) Broadcast ¶
Example ¶
hub := NewHub()
hub.clients[&Client{send: make(chan Message, 1)}] = true
_ = hub.Broadcast(Message{Data: "ok"})
func (*Hub) ChannelSubscriberCount ¶
Example ¶
hub := NewHub()
_ = hub.ChannelSubscriberCount("build")
func (*Hub) ClientCount ¶
Example ¶
hub := NewHub() _ = hub.ClientCount()
func (*Hub) HandleWebSocket ¶
func (h *Hub) HandleWebSocket(w http.ResponseWriter, r *http.Request)
Example ¶
var hub *Hub
hub.HandleWebSocket(httptest.NewRecorder(), httptest.NewRequest("GET", "/ws", nil))
func (*Hub) Handler ¶
func (h *Hub) Handler() http.HandlerFunc
Example ¶
hub := NewHub() _ = hub.Handler()
func (*Hub) Run ¶
Example ¶
ctx, cancel := context.WithCancel(context.Background()) cancel() hub := NewHub() hub.Run(ctx)
func (*Hub) SendToChannel ¶
Example ¶
hub := NewHub()
client := &Client{send: make(chan Message, 1)}
_ = hub.Subscribe(client, "build")
_ = hub.SendToChannel("build", Message{Data: "ok"})
type MessageType ¶
type MessageType string
const ( TypeEvent MessageType = "event" TypeSubscribe MessageType = "subscribe" )
Click to show internal directories.
Click to hide internal directories.