Added events feature + rewrote router.go api/v1

This commit is contained in:
2023-06-11 12:09:27 +02:00
parent 7c111f97ab
commit 77ac3e548d
7 changed files with 95 additions and 14 deletions

View File

@ -0,0 +1,27 @@
package services
import "github.com/gofiber/contrib/websocket"
type EventsService struct {
clients map[*websocket.Conn]interface{}
}
func NewEventsService() *EventsService {
return &EventsService{
clients: make(map[*websocket.Conn]interface{}),
}
}
func (es *EventsService) AddConnection(ws *websocket.Conn) {
es.clients[ws] = nil
}
func (es *EventsService) RemoveConnection(ws *websocket.Conn) {
delete(es.clients, ws)
}
func (es *EventsService) Broadcast(msg interface{}) {
for connection := range es.clients {
go connection.WriteJSON(msg)
}
}