mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-05-07 01:55:57 +00:00
27 lines
509 B
Go
27 lines
509 B
Go
package common
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
type Event struct {
|
|
Type string `json:"type"`
|
|
Data any `json:"data,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
func (e Event) ToJSON() ([]byte, error) {
|
|
return json.Marshal(e)
|
|
}
|
|
|
|
type EventDestination interface {
|
|
Send(event Event) error
|
|
Is(dest EventDestination) bool
|
|
}
|
|
|
|
type EventRouter interface {
|
|
HandleEvent(event Event, source EventDestination)
|
|
AddEventDestination(dest EventDestination)
|
|
RemoveEventDestination(dest EventDestination)
|
|
}
|