diff --git a/internal/ephemeral_store.go b/internal/ephemeral_store.go new file mode 100644 index 0000000..8545876 --- /dev/null +++ b/internal/ephemeral_store.go @@ -0,0 +1,12 @@ +package internal + +// EphemeralStore loads an empty state and discards everything on save +type EphemeralStore struct{} + +func (EphemeralStore) Load() (map[string]*FillerQueue, error) { + return make(map[string]*FillerQueue), nil +} + +func (EphemeralStore) Save(map[string]*FillerQueue) error { + return nil +} diff --git a/internal/report.go b/internal/report.go index 1020fbc..700346c 100644 --- a/internal/report.go +++ b/internal/report.go @@ -53,6 +53,7 @@ type ReportWriter interface { type optionals struct { selector Selector + store Store } func applyOptions(defaults optionals, opts []Option) optionals { @@ -64,20 +65,32 @@ func applyOptions(defaults optionals, opts []Option) optionals { type Option func(*optionals) +// Selector returns true if a record should be selected for processing, false otherwise. +type Selector func(Record) bool + func WithSelector(s Selector) Option { return func(o *optionals) { o.selector = s } } -// Selector returns true if a record should be selected for processing, false otherwise. -type Selector func(Record) bool +type Store interface { + Load() (map[string]*FillerQueue, error) + Save(map[string]*FillerQueue) error +} + +func WithStore(s Store) Option { + return func(o *optionals) { + o.store = s + } +} // BuildReport reads records from a RecordReader and, if the record passes the Selector, it is // processed into the ReportWriter. func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter, options ...Option) error { optionals := applyOptions(optionals{ selector: Any(), + store: EphemeralStore{}, }, options) buys := make(map[string]*FillerQueue)