...

Package GOEventBus

import "github.com/Shibbaz/GOEventBus"
Overview
Index

Overview ▾

Variables

var EventStoreDB *sql.DB

func SetEventStoreDB

func SetEventStoreDB(psqlInfo string)

Setting database connection

type Dispatcher

type Dispatcher map[string]func(*map[string]any) (map[string]interface{}, error)

type Event

type Event struct {
    Id         string
    Projection any
    Args       map[string]any
}

func NewEvent

func NewEvent(projection any, args map[string]any) Event

Event constructor

type EventStore

type EventStore struct {
    Dispatcher *Dispatcher
    Done       chan bool

    Wg sync.WaitGroup
    // contains filtered or unexported fields
}

func NewEventStore

func NewEventStore(dispatcher *Dispatcher) *EventStore

Eventstore constructor

func (*EventStore) Broadcast

func (eventstore *EventStore) Broadcast() error

Broadcasts every published event

func (*EventStore) GetEvent

func (eventstore *EventStore) GetEvent() any

Get event from sync.Pool

func (*EventStore) Publish

func (eventstore *EventStore) Publish(event Event)

Subscribing event

func (*EventStore) Query

func (eventstore *EventStore) Query(projection string) map[string](map[string]any)

querying database for events of projections'

func (*EventStore) Run

func (eventstore *EventStore) Run()

func (*EventStore) Setup

func (eventstore *EventStore) Setup(dbname string)

Setting up database and creating table

type EventStoreListener

type EventStoreListener struct {
    OnDescription chan string
    OnBye         chan bool
}

type EventStoreNode

type EventStoreNode struct {
    Listner EventStoreListener
    DC      webrtc.DataChannel
    // contains filtered or unexported fields
}

func NewEventStoreNode

func NewEventStoreNode(dispatcher Dispatcher) *EventStoreNode

EventStoreNode constructor

func (*EventStoreNode) HandleDataChannel

func (eventstore *EventStoreNode) HandleDataChannel(id string, event *Event)

func (*EventStoreNode) Publish

func (eventstore *EventStoreNode) Publish(event string)

Sending bytes over datachannels to publish events and send it in database Serializing data before inserting it to database

func (*EventStoreNode) Subscribe

func (eventstore *EventStoreNode) Subscribe(event Event)

Usecase of datachannel, event is encoded into bytes and send to another peer (look into Publish func)

type Serializer

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

func NewSerializer

func NewSerializer() *Serializer

Serializer constructor

func (*Serializer) Deserialize

func (serializer *Serializer) Deserialize(data []byte) map[string]any

Deserialize deserializes data []byte to map[string]any

func (*Serializer) Serialize

func (serializer *Serializer) Serialize(data map[string]any) []byte

Serialize serializes data into []byte