fix
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Package storage implements persistent storage for telemetry data.
|
||||
package storage
|
||||
|
||||
import (
|
||||
@@ -11,10 +12,12 @@ import (
|
||||
"github.com/natefinch/lumberjack"
|
||||
)
|
||||
|
||||
// FileStore implements the Store interface using a file-based logger.
|
||||
type FileStore struct {
|
||||
logger *lumberjack.Logger
|
||||
}
|
||||
|
||||
// NewFileStore creates a new FileStore instance that writes to filename.
|
||||
func NewFileStore(filename string) *FileStore {
|
||||
return &FileStore{
|
||||
logger: &lumberjack.Logger{
|
||||
@@ -27,6 +30,7 @@ func NewFileStore(filename string) *FileStore {
|
||||
}
|
||||
}
|
||||
|
||||
// Append saves a new history entry to the file store.
|
||||
func (fs *FileStore) Append(ctx context.Context, entry websocket.HistoryEntry) error {
|
||||
data, err := json.Marshal(entry)
|
||||
if err != nil {
|
||||
@@ -36,10 +40,12 @@ func (fs *FileStore) Append(ctx context.Context, entry websocket.HistoryEntry) e
|
||||
return err
|
||||
}
|
||||
|
||||
// GetHistory retrieves historical entries from the file store.
|
||||
func (fs *FileStore) GetHistory(ctx context.Context, limit int) ([]websocket.HistoryEntry, error) {
|
||||
return fs.Search(ctx, "", limit)
|
||||
}
|
||||
|
||||
// Search searches for historical entries in the file store matching the query.
|
||||
func (fs *FileStore) Search(ctx context.Context, query string, limit int) ([]websocket.HistoryEntry, error) {
|
||||
if limit <= 0 {
|
||||
limit = 50 // Default to a manageable number
|
||||
@@ -52,7 +58,9 @@ func (fs *FileStore) Search(ctx context.Context, query string, limit int) ([]web
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
var matchingLines []string
|
||||
scanner := bufio.NewScanner(file)
|
||||
|
||||
Reference in New Issue
Block a user