const PluginName … type BatchConfig … type bufferedBackend … var _ … // NewBackend returns a buffered audit backend that wraps delegate backend. // Buffered backend automatically runs and shuts down the delegate backend. func NewBackend(delegate audit.Backend, config BatchConfig) audit.Backend { … } func (b *bufferedBackend) Run(stopCh <-chan struct{ … } // Shutdown blocks until stopCh passed to the Run method is closed and all // events added prior to that moment are batched and sent to the delegate backend. func (b *bufferedBackend) Shutdown() { … } // processIncomingEvents runs a loop that collects events from the buffer. When // b.stopCh is closed, processIncomingEvents stops and closes the buffer. func (b *bufferedBackend) processIncomingEvents(stopCh <-chan struct{ … } // collectEvents attempts to collect some number of events in a batch. // // The following things can cause collectEvents to stop and return the list // of events: // // - Maximum number of events for a batch. // - Timer has passed. // - Buffer channel is closed and empty. // - stopCh is closed. func (b *bufferedBackend) collectEvents(timer <-chan time.Time, stopCh <-chan struct{ … } // processEvents process the batch events in a goroutine using delegateBackend's ProcessEvents. func (b *bufferedBackend) processEvents(events []*auditinternal.Event) { … } func (b *bufferedBackend) ProcessEvents(ev ...*auditinternal.Event) bool { … } func (b *bufferedBackend) String() string { … }