hub

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package hub is a event hub system managing events by distributing them to subscribed channels

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	Subscribers map[chan ServerSideEvent]bool
	// contains filtered or unexported fields
}

Hub is the actual event Hub

func New

func New(log *logrus.Logger) *Hub

New creates a new event hub

func (*Hub) Broadcast

func (h *Hub) Broadcast(event ServerSideEvent)

Broadcast broadcasts the given event to all of the subscribers

func (*Hub) Register

func (h *Hub) Register(channelToRegister chan ServerSideEvent)

Register adds a channel to the event hub

func (*Hub) Run

func (h *Hub) Run()

Run starts the broadcasting of the events

func (*Hub) Unregister

func (h *Hub) Unregister(channelToUnregister chan ServerSideEvent)

Unregister removes a channel from the event hub

type ServerSideEvent

type ServerSideEvent struct {
	Typus        ServerSideEventTypus `json:"typus"`
	OptionalData interface{}          `json:"optional_data,omitempty"`
}

ServerSideEvent simulates a event happening on the Server

type ServerSideEventTypus

type ServerSideEventTypus string

ServerSideEventTypus is an alias for string used for ServerSideEvents

const (
	HobbitCreated  ServerSideEventTypus = "HobbitCreated"
	HobbitDeleted  ServerSideEventTypus = "HobbitDeleted"
	HobbitModified ServerSideEventTypus = "HobbitModified"
	RecordCreated  ServerSideEventTypus = "RecordCreated"
	RecordDeleted  ServerSideEventTypus = "RecordDeleted"
	RecordModified ServerSideEventTypus = "RecordModified"
)

constants of EventTypus

Jump to

Keyboard shortcuts

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