package ops import ( "git.kevincotugno.com/kcotugno/tacitus" ) type Registrar struct { Database tacitus.DatabaseClientService Listener tacitus.ListenerService logger tacitus.Logger } func (r *Registrar) Record(products ...string) error { if err := r.Listener.Open(); err != nil { return err } r.record() r.Listener.Subscribe(products...) return nil } func (r *Registrar) SetLogger(logger tacitus.Logger) { r.Listener.SetLogger(logger) r.logger = logger } func (r *Registrar) record() { go func() { for t := range r.Listener.Stream() { go func(trade tacitus.Trade) { _, err := r.Database.TradeService().CreateTrade(trade) if err != nil { r.logger.Info("Error inserting trade: %v", err) } }(t) } }() go func() { for err := range r.Listener.Error() { r.logger.Info("Registrar received error: %v", err) } }() }