test(nest): live-model crow delivery in the nest; ReadEvents log helper (#13)
This commit is contained in:
1 parent
ca22c16a53
commit
0da8cf2bb6
2 files changed
+118
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@@ -55,3 +56,23 @@ func (l *FlightLog) Write(e Event) {
|
||||
}
|
||||
|
||||
func (l *FlightLog) Close() error { return l.f.Close() }
|
||||
|
||||
// ReadEvents parses a flight log file back into events, in the order written.
|
||||
func ReadEvents(path string) ([]Event, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []Event
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
if strings.TrimSpace(line) == "" {
|
||||
continue
|
||||
}
|
||||
var e Event
|
||||
if err := json.Unmarshal([]byte(line), &e); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, e)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
Reference in new issue
Block a user