feat: add audit/tracker.go
This commit is contained in:
20
audit/tracker.go
Normal file
20
audit/tracker.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package audit
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
type Tracker struct { windows map[string]*Window }
|
||||||
|
|
||||||
|
func NewTracker() *Tracker { return &Tracker{windows: make(map[string]*Window)} }
|
||||||
|
|
||||||
|
func (t *Tracker) Accept(frame Frame) string {
|
||||||
|
if strings.TrimSpace(frame.Device) == "" { return "missing device" }
|
||||||
|
window := t.windows[frame.Device]
|
||||||
|
if window == nil { window = &Window{}; t.windows[frame.Device] = window }
|
||||||
|
return window.Observe(frame.Sequence)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tracker) Snapshot() map[string]Summary {
|
||||||
|
result := make(map[string]Summary, len(t.windows))
|
||||||
|
for device, window := range t.windows { result[device] = window.Summary }
|
||||||
|
return result
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user