better handling

This commit is contained in:
2026-04-05 09:47:25 +02:00
parent 0fd17e4944
commit 988ea1d919
5 changed files with 357 additions and 282 deletions
+4 -3
View File
@@ -18,7 +18,7 @@ const (
)
type HistoryProvider interface {
GetHistory() []HistoryEntry
GetHistory(limit int) []HistoryEntry
}
type HistoryEntry struct {
@@ -72,7 +72,7 @@ func (s *Server) HandleConnections(w http.ResponseWriter, r *http.Request) {
// // Send history to new client
// if s.historyProvider != nil {
// history := s.historyProvider.GetHistory()
// history := s.historyProvider.GetHistory(50)
// for _, entry := range history {
// if data, err := json.Marshal(entry); err == nil {
// if err := ws.WriteMessage(websocket.TextMessage, data); err != nil {
@@ -117,7 +117,8 @@ func (s *Server) SendHistory(ws *websocket.Conn) {
s.mutex.Lock()
defer s.mutex.Unlock()
history := s.historyProvider.GetHistory() // Assuming GetHistory() returns the history data
// Default to 100 entries for new socket connections if not otherwise specified
history := s.historyProvider.GetHistory(100)
for _, entry := range history {
data, err := json.Marshal(entry)
if err != nil {