Added events feature + rewrote router.go api/v1
This commit is contained in:
27
internal/events/services/events_service.go
Normal file
27
internal/events/services/events_service.go
Normal 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user