better handling
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user