mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-05-07 10:05:54 +00:00
work towards decoupling api from router
This commit is contained in:
26
internal/common/events.go
Normal file
26
internal/common/events.go
Normal file
@@ -0,0 +1,26 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user