32 lines
551 B
Go
32 lines
551 B
Go
package controller
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/r3labs/sse/v2"
|
|
)
|
|
|
|
const ServerSideEvent = "sse"
|
|
|
|
type NotifierType uint
|
|
|
|
const (
|
|
Create NotifierType = iota
|
|
Delete
|
|
DeleteAll
|
|
)
|
|
|
|
type StatusMessage struct {
|
|
Type NotifierType `json:"type"`
|
|
Payload []Order `json:"payload"`
|
|
}
|
|
|
|
func (c *Controller) setupEventChannel() {
|
|
c.SSE.AutoReplay = false
|
|
c.SSE.CreateStream(ServerSideEvent)
|
|
}
|
|
|
|
func (c *Controller) publishMessage(msg StatusMessage) {
|
|
json, _ := json.Marshal(msg)
|
|
c.SSE.Publish(ServerSideEvent, &sse.Event{Data: json})
|
|
}
|