commit inicial do projeto
This commit is contained in:
20
internal/ws/events.go
Normal file
20
internal/ws/events.go
Normal file
@ -0,0 +1,20 @@
|
||||
package ws
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Emit envia um evento para todos os clientes conectados
|
||||
func Emit(eventType string, data any) {
|
||||
msg := map[string]any{
|
||||
"type": eventType,
|
||||
"data": data,
|
||||
}
|
||||
jsonMsg, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
fmt.Println("Erro ao serializar evento WebSocket:", err)
|
||||
return
|
||||
}
|
||||
broadcast <- jsonMsg
|
||||
}
|
||||
Reference in New Issue
Block a user