Cleaned up a bit
This commit is contained in:
parent
e668d62b57
commit
e57121715e
2 changed files with 9 additions and 9 deletions
|
@ -31,7 +31,7 @@ func SSEDemoSend(c echo.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
lib.SendSSE(channel, message)
|
lib.SSEServer.SendSSE(channel, message)
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, map[string]string{"status": "message sent"})
|
return c.JSON(http.StatusOK, map[string]string{"status": "message sent"})
|
||||||
}
|
}
|
||||||
|
|
16
lib/sse.go
16
lib/sse.go
|
@ -52,15 +52,15 @@ func (s *SSEServerType) ClientCount(channel string) int {
|
||||||
return len(s.clients[channel])
|
return len(s.clients[channel])
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendSSE(channel string, message string) error {
|
func (s *SSEServerType) SendSSE(channel string, message string) {
|
||||||
SSEServer.mu.Lock()
|
s.mu.Lock()
|
||||||
defer SSEServer.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
for client := range SSEServer.clients[channel] {
|
go func() {
|
||||||
client <- message
|
for client := range s.clients[channel] {
|
||||||
}
|
client <- message
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
LogDebug.Printf("\nMessage broadcast on channel %s: %s\n", channel, message)
|
LogDebug.Printf("\nMessage broadcast on channel %s: %s\n", channel, message)
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue