ScuttleBot

scuttlebot / internal / bots / auditbot / store.go
Source Blame History 25 lines
8fe9b10… lmata 1 package auditbot
8fe9b10… lmata 2
8fe9b10… lmata 3 import "sync"
8fe9b10… lmata 4
8fe9b10… lmata 5 // MemoryStore is an append-only in-memory Store for testing.
8fe9b10… lmata 6 type MemoryStore struct {
8fe9b10… lmata 7 mu sync.Mutex
8fe9b10… lmata 8 entries []Entry
8fe9b10… lmata 9 }
8fe9b10… lmata 10
8fe9b10… lmata 11 func (s *MemoryStore) Append(e Entry) error {
8fe9b10… lmata 12 s.mu.Lock()
8fe9b10… lmata 13 defer s.mu.Unlock()
8fe9b10… lmata 14 s.entries = append(s.entries, e)
8fe9b10… lmata 15 return nil
8fe9b10… lmata 16 }
8fe9b10… lmata 17
8fe9b10… lmata 18 // All returns a snapshot of all audit entries.
8fe9b10… lmata 19 func (s *MemoryStore) All() []Entry {
8fe9b10… lmata 20 s.mu.Lock()
8fe9b10… lmata 21 defer s.mu.Unlock()
8fe9b10… lmata 22 out := make([]Entry, len(s.entries))
8fe9b10… lmata 23 copy(out, s.entries)
8fe9b10… lmata 24 return out
8fe9b10… lmata 25 }

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button