bundle chans to struct

This commit is contained in:
Dominic Breuker
2018-03-29 08:51:03 +02:00
parent 84db6dd806
commit d4e20c3629

View File

@@ -29,6 +29,12 @@ type PSScanner interface {
Run(triggerCh chan struct{}) (chan string, chan error) Run(triggerCh chan struct{}) (chan string, chan error)
} }
type chans struct {
sigCh chan os.Signal
fsEventCh chan string
psEventCh chan string
}
func Start(cfg *config.Config, b *Bindings, sigCh chan os.Signal) chan struct{} { func Start(cfg *config.Config, b *Bindings, sigCh chan os.Signal) chan struct{} {
b.Logger.Infof("Config: %+v", cfg) b.Logger.Infof("Config: %+v", cfg)
@@ -39,25 +45,30 @@ func Start(cfg *config.Config, b *Bindings, sigCh chan os.Signal) chan struct{}
triggerEvery(100*time.Millisecond, triggerCh) triggerEvery(100*time.Millisecond, triggerCh)
exit := printOutput(cfg, b, sigCh, fsEventCh, psEventCh) chans := &chans{
sigCh: sigCh,
fsEventCh: fsEventCh,
psEventCh: psEventCh,
}
exit := printOutput(cfg, b, chans)
return exit return exit
} }
func printOutput(cfg *config.Config, b *Bindings, sigCh chan os.Signal, fsEventCh chan string, psEventCh chan string) chan struct{} { func printOutput(cfg *config.Config, b *Bindings, chans *chans) chan struct{} {
exit := make(chan struct{}) exit := make(chan struct{})
fsEventColor, psEventColor := getColors(cfg.Colored) fsEventColor, psEventColor := getColors(cfg.Colored)
go func() { go func() {
for { for {
select { select {
case se := <-sigCh: case se := <-chans.sigCh:
b.Logger.Infof("Exiting program... (%s)", se) b.Logger.Infof("Exiting program... (%s)", se)
exit <- struct{}{} exit <- struct{}{}
case fe := <-fsEventCh: case fe := <-chans.fsEventCh:
if cfg.LogFS { if cfg.LogFS {
b.Logger.Eventf(fsEventColor, "FS: %+v", fe) b.Logger.Eventf(fsEventColor, "FS: %+v", fe)
} }
case pe := <-psEventCh: case pe := <-chans.psEventCh:
if cfg.LogPS { if cfg.LogPS {
b.Logger.Eventf(psEventColor, "CMD: %+v", pe) b.Logger.Eventf(psEventColor, "CMD: %+v", pe)
} }