events

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: EUPL-1.2 Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

func NewHub

func NewHub() *Hub
Example
hub := NewHub()
_ = hub.ClientCount()

func (*Hub) Broadcast

func (h *Hub) Broadcast(msg Message) core.Result
Example
hub := NewHub()
hub.clients[&Client{send: make(chan Message, 1)}] = true
_ = hub.Broadcast(Message{Data: "ok"})

func (*Hub) ChannelSubscriberCount

func (h *Hub) ChannelSubscriberCount(channel string) int
Example
hub := NewHub()
_ = hub.ChannelSubscriberCount("build")

func (*Hub) ClientCount

func (h *Hub) ClientCount() int
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

func (h *Hub) Run(ctx context.Context)
Example
ctx, cancel := context.WithCancel(context.Background())
cancel()
hub := NewHub()
hub.Run(ctx)

func (*Hub) SendToChannel

func (h *Hub) SendToChannel(channel string, msg Message) core.Result
Example
hub := NewHub()
client := &Client{send: make(chan Message, 1)}
_ = hub.Subscribe(client, "build")
_ = hub.SendToChannel("build", Message{Data: "ok"})

func (*Hub) Subscribe

func (h *Hub) Subscribe(client *Client, channel string) core.Result
Example
hub := NewHub()
client := &Client{send: make(chan Message, 1)}
_ = hub.Subscribe(client, "build")

type Message

type Message struct {
	Type      MessageType `json:"type"`
	Channel   string      `json:"channel,omitempty"`
	ProcessID string      `json:"processId,omitempty"`
	Data      any         `json:"data,omitempty"`
	Timestamp time.Time   `json:"timestamp"`
}

type MessageType

type MessageType string
const (
	TypeEvent     MessageType = "event"
	TypeSubscribe MessageType = "subscribe"
)

Jump to

Keyboard shortcuts

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