Restructure project
This commit is contained in:
parent
e44e7caa11
commit
16b2f17301
46 changed files with 1744 additions and 1265 deletions
25
internal/controller/events.go
Normal file
25
internal/controller/events.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/r3labs/sse/v2"
|
||||
"gitlab.unjx.de/flohoss/cafe-plaetschwiesle/internal/types"
|
||||
)
|
||||
|
||||
const ServerSideEvent = "sse"
|
||||
|
||||
type StatusMessage struct {
|
||||
Type types.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})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue